Skip to content

feat(c/driver/postgresql): expose numeric result type modifiers - #4798

Open
besquared wants to merge 4 commits into
apache:mainfrom
tdminc:postgresql-numeric-typmod
Open

besquared wants to merge 4 commits into
apache:mainfrom
tdminc:postgresql-numeric-typmod

Conversation

@besquared

@besquared besquared commented Sep 22, 2026

Copy link
Copy Markdown

Summary

Carry libpq PQfmod into numeric result-field metadata as POSTGRESQL:typmod. The proposed spelling follows POSTGRESQL:type and is open to review. Numeric values remain UTF-8 with the existing opaque extension; there is no numeric conversion, inference, buffering, or additional query.

The modifier is preserved by COPY result description and the non-COPY reader. Only numeric fields with an explicitly supplied modifier receive the key; -1 remains distinguishable from absent metadata. Parameter schemas and catalog discovery are unchanged.

Motivation and scope

PostgreSQL already supplies declared numeric precision and scale through the result-column type modifier returned by PQfmod, but that information is not currently carried into the driver's Arrow result fields. A downstream consumer receives the exact numeric string without those declared bounds. Preserving the modifier lets consumers make informed conversion decisions without parsing SQL or requiring callers to supply types that PostgreSQL has already described. When PostgreSQL supplies no modifier, this change preserves -1; it does not invent precision or scale.

This is deliberately narrower than converting numeric values into Arrow decimals, inferring bounds from returned values, or accepting a caller-requested output schema. It preserves information already supplied by PostgreSQL while leaving the value representation and conversion policy unchanged. Those features could use this metadata, but this change does not implement or replace them.

Relative to the related work, this carries the result modifier discussed in #758 alongside the type-name metadata added in #4687. It does not implement the requested-output-schema proposal in #1514 or the numeric conversion option in #1521.

Tests

  • Built the PostgreSQL driver and both native test executables against upstream main with GCC 13.3, Debug, warnings-as-errors.
  • PostgresTypeTest.* and PostgresStatementTest.NumericTypeModifier: 9 passed against PostgreSQL over a read-only connection.
  • PostgreSQL COPY reader/writer test executable: 75 passed.
  • Integration coverage compares ExecuteSchema and execution for COPY on/off, declared numeric, unconstrained numeric, expression results, NULL, empty results, and unaffected integer columns; checks unchanged string values.
  • Type-level tests include negative-scale and scale-greater-than-precision modifiers.
  • clang-format 18.1.7, cpplint 2.0.2 with repository options, and git diff --check passed. The complete multi-language pre-commit suite and full PostgreSQL integration suite were not run.

Related: the PQfmod discussion in #758 and numeric metadata in #4687. This exposes existing result metadata and does not implement #1514 or #1521.

Closes #4797

Assisted-by: OpenAI Codex

@besquared
besquared requested a review from lidavidm as a code owner September 22, 2026 03:22

This branch has not been deployed

No deployments
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.

feat(c/driver/postgresql): expose numeric result type modifiers

1 participant