Numeric // Decimal Postgres types are inferred as strings and expect string as an input as well
5 Replies
That is intentional - numeric and decimal are used to store values with huge precision/number of digits, so it only makes sense to store them as strings. For regular numbers, you can use
integer
, bigint
, doublePrecision
, real
.
Otherwise, how would you represent a number with 65 digits after the decimal point in JS?Ah I see, so they're just converted to
string
to avoid losing precision in typescript ?
if I pass a string representation to LTE and GTE queries, would is still correctly filter by Less Than and Greater Than?I guess it depends on Postgres - if it supports LTE/GTE on numerics, I don't see why it shouldn't work.
Sounds good - for our use case we just decided to use double precision since it was within the precision limits we wanted and its better to not deal with string numbers in typescript
That's how we planned it to be used - if your precision limits can be expressed in JS, use double precision, otherwise use numeric with strings