Skip to content

Conversation

@hariso
Copy link
Contributor

@hariso hariso commented May 19, 2025

Description

Closes #292.

This PR adds support for reading numeric/decimal values and writing those. The values are read into big.Rat values. big.Rat values are also written into numeric/decimal columns in the database.

To convert a big.Rat value (which is a fractional number) into a numeric value, we need to calculate the ratio up to a given precision, which is retrieved from the database. The precision/scale from the database is cached and expires after 5 minutes.

Quick checks:

  • I have followed the Code Guidelines.
  • There is no other pull request for the same update/change.
  • I have written unit tests.
  • I have made sure that the PR is of reasonable size and can be easily reviewed.

@hariso hariso force-pushed the haris/pg-numeric-to-big-rat branch from b6c5771 to 31939cf Compare May 19, 2025 18:34
@hariso hariso changed the title Read Postgres' NUMERIC as big.Rat Supporting reading and writing NUMERIC values without loss of precision May 20, 2025
@hariso hariso changed the title Supporting reading and writing NUMERIC values without loss of precision Supporting reading and writing numeric/decimal values without loss of precision May 20, 2025
@hariso hariso marked this pull request as ready for review May 20, 2025 08:15
@hariso hariso requested a review from a team as a code owner May 20, 2025 08:15
@hariso hariso enabled auto-merge (squash) May 29, 2025 13:33
@hariso hariso requested a review from raulb May 29, 2025 16:13
Copy link
Contributor

@raulb raulb left a comment

Choose a reason for hiding this comment

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

Changed looked good, thank you @hariso

@hariso
Copy link
Contributor Author

hariso commented May 30, 2025

Thank you @raulb and @lyuboxa for the reviews!

@hariso hariso merged commit 25f925d into main May 30, 2025
3 checks passed
@hariso hariso deleted the haris/pg-numeric-to-big-rat branch May 30, 2025 18:10
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.

Supporting reading and writing numeric/decimal values without loss of precision

4 participants