Open mgartner opened 2 years ago
The issue can be observed with explicit casts in the demo. In the example below, the result value should be 18755000.
defaultdb> SELECT 18754999.99::FLOAT8::FLOAT4::FLOAT8;
float8
-------------------
1.875499999e+07
(1 row)
root cause is float to float casts do nothing:
for int family, it is done here...
float4 is actually handled pretty badly.
parsing example:
root@127.0.0.1:26257/defaultdb> select '4e+38'::float4;
float4
------------
Infinity
(1 row)
vs psql:
otan=# select '4e+38'::float4;
ERROR: "4e+38" is out of range for type real
LINE 1: select '4e+38'::float4;
urgh, this is already committed into the DB for some people as well. would need to test whether any fix breaks those cases...
in fact, since we store Float4 as Float8, all arithmetic is done using Float8 so even more stuff is probably wrong?
in fact, since we store Float4 as Float8, all arithmetic is done using Float8 so even more stuff is probably wrong?
Yikes, I think you're probably correct about that. Looks like this won't be a quick win...
The root problem here seems to be https://github.com/cockroachdb/cockroach/issues/48613
It looks like this was partially fixed by #82022. See: https://github.com/cockroachdb/cockroach/commit/4d16dbfb078c071aeeb7f964eb075f443d0aa091#diff-c49e1bdbc0004860cadef9d5e1e4d3e2c18b89a254ad9f4885e6c929ff2a5e43R172-R173
But it's not clear to me how that change fixed these tests and the example test in the description above. Maybe @rafiss has an idea?
Regardless, I think this is still an issue as seen here: https://github.com/cockroachdb/cockroach/commit/4d16dbfb078c071aeeb7f964eb075f443d0aa091#diff-c49e1bdbc0004860cadef9d5e1e4d3e2c18b89a254ad9f4885e6c929ff2a5e43R1405-R1411
Another related issue: https://github.com/cockroachdb/cockroach/issues/84326
When inserting a float into a
FLOAT4
column, or casting a value to aFLOAT4
, CRDB does not correctly truncate the precision of the float to fit within aFLOAT4
. This is present in v21.2.2, so it's not a regression from the assignment cast changes that were merged after v21.2, but it is related to assignment casts.In Postgres:
In CRDB (using logic test because the demo client will truncate floats):
Jira issue: CRDB-11718