Repository navigation
gcvctor: add PGNumericValueExact for the PG-dialect numeric value space - #257
Merged
Merged
Conversation
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>
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #249 (filed from the spanpg phase-3 work, where the 9-digit rounding of
PGNumericValuehad to be documented as a hazard on spanpg'sEncodeOptions).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 newErrInexactNumeric), so values the PG-dialectnumerictype can represent exactly are never silently rounded.MustPGNumericValueExactjoins the fixture family. A contrast test pins the rounding behavior this constructor exists to avoid (1e-17→0.000000000underPGNumericValue).Follow-up after release: spanpg updates its
EncodeOptionshazard doc to point here.🤖 Generated with Claude Code