Skip to content

Add detection of out-of-bound NUMERICs - #562

Merged
staticlibs merged 1 commit into
duckdb:mainfrom
staticlibs:out_of_bound_numerics
Sep 1, 2026
Merged

Add detection of out-of-bound NUMERICs#562
staticlibs merged 1 commit into
duckdb:mainfrom
staticlibs:out_of_bound_numerics

Conversation

@staticlibs

Copy link
Copy Markdown
Member

This PR adds detection of NaN, Infinity and -Infinity values of Postgres' NUMERIC colums with the following logic:

  • for bound NUMERIC(p,s) columns:

    • if options pg_numeric_nan_as_null is enabled (default: TRUE) - NULL is returned on NaN value
    • otherwise, an error is thrown
    • Postgres bound NUMERIC(p,s) columns cannot hold Infinity or -Infinity values
  • for unbound NUMERIC columns:

    • if option pg_numeric_as_varchar is enabled (default: FALSE) - then a VARCHAR representation is returned as NaN, Infinity or -Infinity string
    • otherwise DOUBLE value is returned holding DuckDB-native NaN, Infinity or -Infinity double number

Testing: new test is added with an out-of-bound coverage of both options and of all NUMERIC storage types.

Ref: duckdb/duckdb#23971

@staticlibs

Copy link
Copy Markdown
Member Author

@jgmills98

Hi! I wonder if you would like to take a look at this PR, whether it does not break the use-cases you covered in #560?

@jgmills98

Copy link
Copy Markdown
Contributor

@staticlibs

It shouldn't break my use-case. Some uses of unbound in the naming could be updated to avoid confusion as it's possible for an unbound numeric to hold ordinary numbers, this is more detecting non-finite/special cases of numerics.

I think setting pg_numeric_nan_as_null to false would be ignored for plain stable scans/attached catalog scans.

@staticlibs
staticlibs force-pushed the out_of_bound_numerics branch from 4313a09 to 6e30a89 Compare September 1, 2026 18:44
staticlibs added a commit to staticlibs/duckdb-postgres that referenced this pull request Sep 1, 2026
This is a backport of the PR duckdb#562 to `v1.5-variegata` stable branch.

This PR adds detection of `NaN`, `Infinity` and `-Infinity` values of
Postgres' `NUMERIC` colums with the following logic:

 - for bound `NUMERIC(p,s)` columns:
   - if options `pg_numeric_nan_as_null` is enabled (default: `TRUE`) -
    `NULL` is returned on `NaN` value
   - otherwise, an error is thrown
   - Postgres bound `NUMERIC(p,s)` columns cannot hold `Infinity` or
    `-Infinity` values

 - for unbound `NUMERIC` columns:
   - if option `pg_numeric_as_varchar` is enabled (default: `FALSE`) -
    then a `VARCHAR` representation is returned as `NaN`, `Infinity` or
    `-Infinity` string
   - otherwise `DOUBLE` value is returned holding DuckDB-native `NaN`,
    `Infinity` or `-Infinity` double number

Testing: new test is added with an out-of-bound coverage of both options
and of all `NUMERIC` storage types.

Ref: duckdb/duckdb#23971
This PR adds detection of `NaN`, `Infinity` and `-Infinity` values of
Postgres' `NUMERIC` colums with the following logic:

 - for bound `NUMERIC(p,s)` columns:
   - if options `pg_numeric_nan_as_null` is enabled (default: `TRUE`) -
    `NULL` is returned on `NaN` value
   - otherwise, an error is thrown
   - Postgres bound `NUMERIC(p,s)` columns cannot hold `Infinity` or
    `-Infinity` values

 - for unbound `NUMERIC` columns:
   - if option `pg_numeric_as_varchar` is enabled (default: `FALSE`) -
    then a `VARCHAR` representation is returned as `NaN`, `Infinity` or
    `-Infinity` string
   - otherwise `DOUBLE` value is returned holding DuckDB-native `NaN`,
    `Infinity` or `-Infinity` double number

Testing: new test is added with an out-of-bound coverage of both options
and of all `NUMERIC` storage types.

Ref: duckdb/duckdb#23971
@staticlibs
staticlibs force-pushed the out_of_bound_numerics branch from 6e30a89 to 46e8cde Compare September 1, 2026 18:59
staticlibs added a commit to staticlibs/duckdb-postgres that referenced this pull request Sep 1, 2026
This is a backport of the PR duckdb#562 to `v1.5-variegata` stable branch.

This PR adds detection of `NaN`, `Infinity` and `-Infinity` values of
Postgres' `NUMERIC` colums with the following logic:

 - for bound `NUMERIC(p,s)` columns:
   - if options `pg_numeric_nan_as_null` is enabled (default: `TRUE`) -
    `NULL` is returned on `NaN` value
   - otherwise, an error is thrown
   - Postgres bound `NUMERIC(p,s)` columns cannot hold `Infinity` or
    `-Infinity` values

 - for unbound `NUMERIC` columns:
   - if option `pg_numeric_as_varchar` is enabled (default: `FALSE`) -
    then a `VARCHAR` representation is returned as `NaN`, `Infinity` or
    `-Infinity` string
   - otherwise `DOUBLE` value is returned holding DuckDB-native `NaN`,
    `Infinity` or `-Infinity` double number

Testing: new test is added with an out-of-bound coverage of both options
and of all `NUMERIC` storage types.

Ref: duckdb/duckdb#23971
@staticlibs

Copy link
Copy Markdown
Member Author

the naming could be updated to avoid confusion

Changed "unbound" (that was intended to be named "out-of-bound", but became ambiguous) to "non-finite".

I think setting pg_numeric_nan_as_null to false would be ignored for plain stable scans/attached catalog scans.

This is a good catch, added type config init there and the test coverage.

@staticlibs
staticlibs merged commit 50dd6aa into duckdb:main Sep 1, 2026
7 checks passed
@staticlibs
staticlibs deleted the out_of_bound_numerics branch September 1, 2026 20:05
staticlibs added a commit that referenced this pull request Sep 1, 2026
This is a backport of the PR #562 to `v1.5-variegata` stable branch.

This PR adds detection of `NaN`, `Infinity` and `-Infinity` values of
Postgres' `NUMERIC` colums with the following logic:

 - for bound `NUMERIC(p,s)` columns:
   - if options `pg_numeric_nan_as_null` is enabled (default: `TRUE`) -
    `NULL` is returned on `NaN` value
   - otherwise, an error is thrown
   - Postgres bound `NUMERIC(p,s)` columns cannot hold `Infinity` or
    `-Infinity` values

 - for unbound `NUMERIC` columns:
   - if option `pg_numeric_as_varchar` is enabled (default: `FALSE`) -
    then a `VARCHAR` representation is returned as `NaN`, `Infinity` or
    `-Infinity` string
   - otherwise `DOUBLE` value is returned holding DuckDB-native `NaN`,
    `Infinity` or `-Infinity` double number

Testing: new test is added with an out-of-bound coverage of both options
and of all `NUMERIC` storage types.

Ref: duckdb/duckdb#23971
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants