cockroachdb / cockroachdb/cockroach
sql: fix integer math edge cases
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
The following edge cases differ in crdb and postgres:
```
SELECT 2 + 2 / 2 AS three;
-- postgres: 3
-- crdb: 3.0000000000000000000
SELECT (-2147483648)::int4 * (-1)::int4;
-- postgres: ERROR: integer out of range
-- crdb: 2147483648
SELECT (-2147483648)::int4 / (-1)::int4;
-- postgres: ERROR: integer out of range
-- crdb: 2147483648.0000000000
SELECT (-9223372036854775808)::int8 / (-1)::int8;
-- postgres: ERROR: bigint out of range
-- crdb: 9223372036854775808.0
SELECT (-9223372036854775808)::int4 / (-1)::int4;
-- postgres: ERROR: bigint out of range
-- crdb: 9223372036854775808.0
SELECT (-9223372036854775808)::int8 / (-1)::int2;
SELECT (-9223372036854775808)::int4 / (-1)::int4;
-- postgres: ERROR: bigint out of range
-- crdb: 9223372036854775808.0
select (1.5::float8)::int8;
-- postgres: 2
-- crdb: 1
select (-1.5::float8)::int8;
-- postgres: -2
-- crdb: -1
```
This was found in pg_regress int4 and int8.
Jira issue: CRDB-33891
Contributor guide
Assessment
This issue has not been assessed yet.