Skip to content

gcvctor: add PGNumericValueExact for the PG-dialect numeric value space - #257

Merged
apstndb merged 1 commit into
mainfrom
feature/pg-numeric-exact
Jun 12, 2026
Merged

apstndb merged 1 commit into
mainfrom
feature/pg-numeric-exact

Conversation

@apstndb

@apstndb apstndb commented Jun 12, 2026

Copy link
Copy Markdown
Owner

Closes #249 (filed from the spanpg phase-3 work, where the 9-digit rounding of PGNumericValue had to be documented as a hazard on spanpg's EncodeOptions).

Implements option 1 from the issue: PGNumericValueExact(*big.Rat) renders the exact decimal at the smallest sufficient scale (reduced denominator must factor into 2^a·5^b; otherwise the new ErrInexactNumeric), so values the PG-dialect numeric type can represent exactly are never silently rounded. MustPGNumericValueExact joins the fixture family. A contrast test pins the rounding behavior this constructor exists to avoid (1e-17 → 0.000000000 under PGNumericValue).

Follow-up after release: spanpg updates its EncodeOptions hazard doc to point here.

🤖 Generated with Claude Code

PGNumericValue formats via spanner.NumericString, silently rounding to
the GoogleSQL 9-fractional-digit scale even though PostgreSQL-dialect
numeric accepts far more. PGNumericValueExact renders the exact decimal
(smallest sufficient scale) and refuses to lose precision: rationals
without a finite decimal expansion return the new ErrInexactNumeric and
nil returns ErrNilNumeric. MustPGNumericValueExact joins must.go per
the fixture convention.

Closes #249.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces PGNumericValueExact and MustPGNumericValueExact to support exact decimal rendering of PostgreSQL-dialect NUMERIC values without losing precision, alongside a helper finiteDecimalScale and corresponding tests. The review feedback suggests a performance optimization in finiteDecimalScale to pre-allocate big.Int variables outside the loop to avoid repeated allocations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread gcvctor/gcvctor.go
@apstndb
apstndb merged commit aef12f9 into main Jun 12, 2026
5 checks passed
@apstndb
apstndb deleted the feature/pg-numeric-exact branch June 12, 2026 09:47
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.

gcvctor: PGNumericValue silently rounds to 9 fractional digits — too lossy for the PostgreSQL dialect

1 participant