I have looked at many questions regarding this problem, but I have not found a solution. Hopefully this is not a duplicate question.
If I do any of:
INSERT INTO `Numbers`(`Number`) VALUES ('NaN')
INSERT INTO `Numbers`(`Number`) VALUES ('Inf')
INSERT INTO `Numbers`(`Number`) VALUES ('+Inf')
I get 0.0 inserted in the table. Sometimes I get:
Error Code: 1265. Data truncated for column 'Number'
I have also tried different casing and spelling, all with the same effect.
I have even tried:
INSERT INTO `Numbers`(`Number`) VALUES ('1111111111111000000000000000000000000000000000000000000000000000')
How do I insert a NaN floating point number into a MySql table?
If it really isn't possible then what is the reasoning? (Maybe I am using the incorrect version of MySql?)
The tables where I am actually using this I don't want to allow NULL values in those columns. So I don't like the idea of replacing NaN with NULL somewhere in the ORM layer
To get an overall idea of how MySQL manipulates numbers you can read the following chapters:
Numeric Type Overview and Numeric Types, including Out-of-Range and Overflow Handling
The last article mentions this:
The server includes
dtoa
, a conversion library that provides the basis for improved conversion between string orDECIMAL
values and approximate-value (FLOAT
/DOUBLE
) numbers[...]
The dtoa library provides conversions with the following properties.
D
represents a value with aDECIMAL
or string representation, andF
represents a floating-point number in native binary (IEEE) format.[...]
conversions are lossless unless
F
is-inf
,+inf
, orNaN
. The latter values are not supported because the SQL standard defines them as invalid values forFLOAT
orDOUBLE
.
In short: