Skip to content

fix(postgres): keep the scale of NUMERIC when decoding into BigDecimal - #4533

Open
Vladimir-Pirotskiy wants to merge 1 commit into
transact-rs:mainfrom
Vladimir-Pirotskiy:fix/bigdecimal-decode-scale
Open

Vladimir-Pirotskiy wants to merge 1 commit into
transact-rs:mainfrom
Vladimir-Pirotskiy:fix/bigdecimal-decode-scale

Conversation

@Vladimir-Pirotskiy

Copy link
Copy Markdown

Does your PR solve an issue?

Fixes #468

Decoding a Postgres NUMERIC into BigDecimal ignored the display scale sent by the server, so the decoded value did not match what psql shows for the same column. This PR uses the scale from the wire format when building the decoded value. I added a regression test that decodes values with different declared scales, including integers and values with trailing zeros; it fails before the fix and passes after it.

Is this a breaking change?

Yes, it is a behavior change. The numeric value stays the same, but the scale is now preserved, so the output of to_string() changes: for a NUMERIC(10, 2) column, 1.5000 becomes 1.50 and 4 becomes 4.00. Code that compares or parses these strings may be affected. See #2838, which made the same change for Decimal.

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.

TryFrom<PgNumeric> for BigDecimal ignores scale value of PgNumeric

1 participant