cockroachdb / cockroachdb/cockroach

sql: fix float cast edge cases

Open
#115,131 0 comments 0 reactions 0 assignees View on GitHub
A-sql-pgcompat C-bug O-pg-regress P-3 T-sql-queries
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.