cockroachdb / cockroachdb/cockroach
sql: fix float cast edge cases
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
The following examples differ between postgres and crdb:
```
select '10e70'::float4;
-- postgres ERROR: "10e70" is out of range for type real
-- crdb: +Inf
select '-10e70'::float4;
-- postgres ERROR: "-10e70" is out of range for type real
-- crdb: -Inf
select '10e-70'::float4;
-- postgres ERROR: "10e-70" is out of range for type real
-- crdb: 0
select '-10e-70'::float4;
-- postgres ERROR: "-10e-70" is out of range for type real
-- crdb: -0
select ('10e70'::float8)::float4;
-- postgres: ERROR: value out of range: overflow
-- crdb: +Inf
select ('10e-70'::float8)::float4;
-- postgres: ERROR: value out of range: underflow
--crdb: 0
SELECT '10e-400'::float8;
-- postgres: ERROR: "10e-400" is out of range for type double precision
--crdb: 0
SELECT '32767.6'::float8::int2;
-- postgres: ERROR: smallint out of range
-- crdb: 32767
SELECT '2147483647.6'::float8::int4;
-- postgres: ERROR: integer out of range
-- crdb: 2147483647
SELECT '-9223372036854775808.5'::float8::int8;
-- postgres: -9223372036854775808
-- crdb: ERROR: integer out of range
```
Found in pg_regress float4 and float8.
Jira issue: CRDB-33901
Contributor guide
Assessment
This issue has not been assessed yet.