6 releases

0.1.5 Sep 7, 2022
0.1.4 Sep 30, 2021
0.1.1 Aug 31, 2021

#979 in Database interfaces

Download history 2060/week @ 2024-07-19 2173/week @ 2024-07-26 1814/week @ 2024-08-02 1122/week @ 2024-08-09 1642/week @ 2024-08-16 1648/week @ 2024-08-23 1643/week @ 2024-08-30 1262/week @ 2024-09-06 1918/week @ 2024-09-13 2534/week @ 2024-09-20 2407/week @ 2024-09-27 2509/week @ 2024-10-04 2447/week @ 2024-10-11 3724/week @ 2024-10-18 2892/week @ 2024-10-25 1772/week @ 2024-11-01

11,271 downloads per month
Used in pg2parquet

MIT license

17KB
365 lines

rust-pg_bigdecimal

A Rust datatype implementation for the Postgres Numeric type (ie the types listed in https://www.postgresql.org/docs/13/datatype-numeric.html under "decimal"/"numeric"), to be used with Rust's "Postgres" library. The full spectrum of Postgres' Numeric value range is supported.

This small Rust package has been created because currently the main "Postgres" library (https://docs.rs/postgres/0.19.1/postgres/index.html) does not provide a native datatype to read/write Numeric values.

We only implement the wire logic of Postgres' Numeric datatype. We didn't rewrite the whole logic of big number manipulation, rather we let that logic be implemented by the already popular BigDecimal package (https://docs.rs/bigdecimal/0.3.0/bigdecimal/).

Specifically, our new Rust datatype PgNumeric is simply an Optional BigDecimal. With None representing the Postgres Numeric value NaN, and all Some(..) representing Postgres Numeric numbers.

Listed on crates.io here: https://crates.io/crates/pg_bigdecimal.

Comparisons between similar packages

  • https://crates.io/crates/rust-decimal provides a rust native type, however it's represented as a 96 bit integer number + scaling bits + 1 sign bit. This means that "only" (quoting only here because it is still a large integer space) a small part of Postgres' Numeric values can be translated. In our case it was not sufficient.

Dependencies

~8–17MB
~247K SLoC