Closed vporton closed 2 years ago
Why do you think it can work?
Where are checks for fractional part (which should lead to failures)?
NUMERIC is an arbitrary precision decimal type, so I'm not sure this conversion is correct. Minimally it needs to handle the fractional part in some way.
Where are checks for fractional part (which should lead to failures)?
Doesn't the below code from my patch fail in the case of a fractional part?
if !buf.is_empty() {
return Err("invalid buffer size".into());
}
No. It is better to read how NUMERIC is sent/receive at PostgreSQL sources[1] and read existing implementations[2].
Tests for unknown (for you) behavior and how data is encoded is «must have».
[2] https://github.com/paupino/rust-decimal/blob/master/src/postgres/driver.rs
P.S. in PG's sources functions which are used in the binary protocol are numeric_recv
(line 991) and numeric_send
(line 1079).
This is not a good idea. 128 bits is 16 bytes. PostgreSQL has a fixed-width 16 byte type: uuid. Ignoring the rendering, if you're going to implement a native store for i128 in PostgreSQL you'd be far better of using this type.
UUID is abused for this already too.
Untested.
Contrived use of
NUMERIC
SQL type, fails on numbers with a fractional part.