cockroachdb / cockroachdb/cockroach

sql: add support for negative scale in decimals

Open
#158,883 0 comments 0 reactions 0 assignees View on GitHub
A-sql-pgcompat C-enhancement T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Postgres allows specifying a negative scale for decimal types. While a positive/zero scale specifies a point _after_ the decimal point to round values, a negative scale specifies a point _before_ the decimal point. Currently, CRDB does not allow specifying a negative scale:
```
root@localhost:26257/defaultdb> select 1::decimal(2, -3);
ERROR: statement ignored: at or near "-": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
select 1::decimal(2, -3)
^
root@localhost:26257/defaultdb> create table t (x decimal(2, -3));
ERROR: statement ignored: at or near "-": syntax error
SQLSTATE: 42601
DETAIL: source SQL:
create table t (x decimal(2, -3))
^
HINT: try \h CREATE TABLE
```
Relevant Postgres docs: https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL

Jira issue: CRDB-57538

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.