Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more database info #88

Open
dveeden opened this issue Nov 21, 2015 · 3 comments
Open

Some more database info #88

dveeden opened this issue Nov 21, 2015 · 3 comments

Comments

@dveeden
Copy link

dveeden commented Nov 21, 2015

A bug I filed about IEEE 754 documentation a while ago for MySQL:
https://bugs.mysql.com/bug.php?id=57519

Support for NaN differs between MySQL and PostgreSQL. I didn't see any information about the 'special' values on http://0.30000000000000004.com

Note that there are different behaviors within one database system:
http://sqlfiddle.com/#!6/12e70/3

CREATE TABLE t1 (f FLOAT);
SELECT 0.1 + 0.2;
INSERT INTO t1 VALUES(0.1),(0.2);
SELECT SUM(f) FROM t1;

With Microsoft SQL Server 2014 this has the following output:

0.3
0.30000000000000004

With MySQL 5.6:

0.3
0.30000000447034836

http://sqlfiddle.com/#!9/2e75e/1

Oracle 11gR2 returns 0.3 in both cases:
http://sqlfiddle.com/#!4/0509e6/4

Note that Oracle has FLOAT and BINARY_FLOAT
http://sqlfiddle.com/#!4/cf223/1

@dveeden
Copy link
Author

dveeden commented Nov 21, 2015

SQLite always returns 0.30000000000000004
http://sqlfiddle.com/#!5/0509e/2

@erikwiffin
Copy link
Owner

If you send me a PR on the subject I'd be happy to merge it.

@sir-sigurd
Copy link

sir-sigurd commented Oct 12, 2018

@dveeden

Note that there are different behaviors within one database system:
http://sqlfiddle.com/#!6/12e70/3

CREATE TABLE t1 (f FLOAT);
SELECT 0.1 + 0.2;
INSERT INTO t1 VALUES(0.1),(0.2);
SELECT SUM(f) FROM t1;

IMO that's more correct:

mysql> CREATE TABLE t1 (f DOUBLE);
Query OK, 0 rows affected (0.10 sec)

mysql> INSERT INTO t1 VALUES(0.1),(0.2);
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> SELECT 0.1e0 + 0.2e0;
+---------------------+
| 0.1e0 + 0.2e0       |
+---------------------+
| 0.30000000000000004 |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT SUM(f) FROM t1;
+---------------------+
| SUM(f)              |
+---------------------+
| 0.30000000000000004 |
+---------------------+
1 row in set (0.00 sec)

Probably it's the same for MS SQL: https://docs.microsoft.com/en-us/sql/t-sql/data-types/constants-transact-sql?view=sql-server-2017#float-and-real-constants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants