cornucopia-rs / cornucopia

Generate type-checked Rust from your PostgreSQL.
Other
755 stars 31 forks source link

Use different type to represent DECIMAL than rust_decimals::Decimal #204

Open xoac opened 1 year ago

xoac commented 1 year ago

Hi cornucopia team, I have found another place where it's hard to work with cornucopia,. It's completely fine to insert 7777777777777777777777777777777777777777777777777777 into PostgreSQL DECIMAL column.

Unfortunately rust_decimal::Decimal::from_str('7777777777777777777777777777777777777777777777777777') will return error so using it to represent DECIMAL is limited.

On possible solution:

  1. add PR for bigdecimal crate to optionally enable support for postgresql?
  2. migrate from rust_decimal to bigdecimal for DECIMAL type
LouisGariepy commented 1 year ago

Looking a bit more into this, it seems like bigdecimal has a number of concerning implementation issues.

The maintainer of rust_decimal has expressed interest in implementing arbitrary precision https://github.com/paupino/rust-decimal/issues/562#issuecomment-1381169106. This might be something we just have to wait for unless we can find another decent big decimal crate.

LouisGariepy commented 1 year ago

See also this comment on why Borsch (a serialization format) didn't implement bigdecimal support https://github.com/near/borsh-rs/pull/91#issuecomment-1277935244.