prisma / quaint

SQL Query AST and Visitor for Rust
Apache License 2.0
583 stars 61 forks source link

Bigdecimal conversion in Postgres is limited to u128 #345

Open snf opened 2 years ago

snf commented 2 years ago

What the title says. The lib doesn't currently support the variable numeric type: https://www.postgresql.org/docs/9.1/datatype-numeric.html which says up to 131072 digits before the decimal point; up to 16383 digits after the decimal point. It crashes if it's used with a numeric type beyond 2^128 because of the code in this function: https://github.com/prisma/quaint/blob/main/src/connector/postgres/conversion/decimal.rs#L81

Opinions on the best way to fix it? I can try submitting a PR if I get some time this week.

I realised that the PR https://github.com/prisma/quaint/pull/344 only stops the crash but the underlying issue is that large numeric types aren't supported

snf commented 2 years ago

This is how that library makes the conversion but unfortunately it doesn't support base 10_000 as needed by quaint https://github.com/rust-num/num-bigint/blob/master/src/biguint/convert.rs#L646 . Could potentially copy and optimize that function in.

richardwu commented 2 years ago

Just ran into this issue as well: I've added a small repro here https://github.com/richardwu/prisma-decimal

zipzapzanigan commented 2 years ago

+1 on this issue, stuck until i can find a fix...