Closed lukoktonos closed 5 months ago
Great callout and a very well written up issue!
I agree with the reasoning regarding capturing and throwing an error. I'd be more than happy to review any patches submitted and really appreciate the offer to help - thank you!
Postgres Numerics have 3 special values:
NaN
,Infinity
, and-Infinity
.The
FromSql
implementation ofDecimal
currently returns an error when parsing Infinity and -Infinity because they have scales beyond what the crate accepts--this is fine, although it may be better to explicitly reject these values rather than relying on the scale, if they are not representable inDecimal
.But for NaN,
from_sql
silently converts it into a0
because it is only checking if thesign
is negative:This is what the raw bytes of NaN look like in
from_sql
:The relevant masks from postgres are:
My proposed logic for handling this is something like:
If that logic sounds good I'd be happy to submit a patch