cockroachdb / cockroachdb/cockroach

sql: fix integer math edge cases

Open
#115,119 1 comment 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 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

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.