Skip to content

TryFrom<PgNumeric> for BigDecimal ignores scale value of PgNumeric #468

Open
@abonander

Description

@abonander

This effectively leaves superfluous zeroes in the fractional part when decoding from PgNumeric:

// should be 3389.5
let pg_numeric = PgNumeric::Number {
    sign: PgNumericSign::Positive,
    digits: [3389, 5000],
    weight: 0,
    scale: 1,
};

assert_eq!(BigDecimal::try_from(pg_numeric).unwrap().to_string(), "3389.5");

This will currently fail because the BigDecimal got decoded as 3389.5000 and it will print that way. This behavior is semantically correct, assuming Postgres sends only extra zeroes (thus the two values are considered equal), however it is potentially confusing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions