paupino / rust-decimal

Decimal number implementation written in pure Rust suitable for financial and fixed-precision calculations.
https://docs.rs/rust_decimal/
MIT License
972 stars 177 forks source link

Fix FromSql for Postgres Numeric NaNs #656

Closed lukoktonos closed 5 months ago

lukoktonos commented 5 months ago

This fixes a bug where from_sql was converting Numeric::NaN to 0 rather than returning an error.

It also returns a more descriptive error message when from_sql is called with Numeric Infinity and -Infinity, which are also not representable in Decimal.

Closes #655

Side note: Unless I am missing something, it seems like the to_from_sql test wasn't actually being run since the postgres feature seems to no longer be a thing. I was able to get it to run by changing the cfg to db-postgres, so I added that to this commit as well.