Skip to content

Fix PostgreSQL connector handling of extreme decimal scales#28414

Merged
findepi merged 5 commits intotrinodb:masterfrom
findepi:findepi/postgresql-decimal-descaling
Feb 25, 2026
Merged

Fix PostgreSQL connector handling of extreme decimal scales#28414
findepi merged 5 commits intotrinodb:masterfrom
findepi:findepi/postgresql-decimal-descaling

Conversation

@findepi
Copy link
Copy Markdown
Member

@findepi findepi commented Feb 23, 2026

Fix PostgreSQL connector handling of decimals with negative scale, and
also of decimals with scale bigger than precision. Before the changes,
both cases were just failing with DecimalType constructor. The code
did not try to handle scale>precision case. For negative scale, the code
assumed it is reported as negative DECIMAL_DIGITS, but that's not the
case.

This also adds PostgreSQL connector type mappings coverage with

  • latest PostgreSQL version
  • PostgreSQL 15, the oldest supported version with NaN, and infinity
    support within NUMERIC type

.

Remove unnecessary constructors taking `boolean exposeFixedPorts`.
Deduplicate constructor overloads taking either image name as either `String`
or `DockerImageName`.
Reorder the logic: handle types mappable to Trino DECIMAL first. Only
then check the decimal mapping value which governs how to map those that
cannot be mapped directly to DECIMAL.

This is meant to be just syntactic code a refactor, with no change in
behavior.
Fix PostgreSQL connector handling of decimals with negative scale, and
also of decimals with scale bigger than precision.  Before the changes,
both cases were just failing with `DecimalType` constructor. The code
did not try to handle scale>precision case. For negative scale, the code
assumed it is reported as negative DECIMAL_DIGITS, but that's not the
case.

This also adds PostgreSQL connector type mappings coverage with

- latest PostgreSQL version
- PostgreSQL 15, the oldest supported version with NaN, and infinity
  support within NUMERIC type
if (0 <= decimalDigits && decimalDigits <= 1000) {
return OptionalInt.of(decimalDigits);
}
if ((2048 - 1000) <= decimalDigits && decimalDigits < 2048) {
Copy link
Copy Markdown
Contributor

@wendigo wendigo Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

introduce const for 2048. move comment to it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it won't make the code more readable; actually the opposite.

@findepi findepi merged commit ae03913 into trinodb:master Feb 25, 2026
26 checks passed
@findepi findepi deleted the findepi/postgresql-decimal-descaling branch February 25, 2026 01:58
@github-actions github-actions bot added this to the 480 milestone Feb 25, 2026
@ebyhr ebyhr mentioned this pull request Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed postgresql PostgreSQL connector

Development

Successfully merging this pull request may close these issues.

Trino fails when PostgreSQL table has a decimal/numeric column with negative scale

3 participants