Open ivan-m opened 7 years ago
I might imagine something from Data.Fixed
or Data.Scientific
might be more appropriate. I'd avoid using Double
for currency calculations.
I second Reid. Also, I prefer that FromField
instances provided with postgresql-simple
reflect the type(s) they support with as full fidelity as possible. IIRC, the money type is also tagged with a currency code. Adding support for Data.Fixed
and/or Data.Scientific
might be acceptable, but really you probably need a type specific to handling money
.
Also keep in mind there is no type checking or anything on ToField
instances in postgresql-simple.
OK, so I'm trying to use Fixed
, but I can't seem to work out how to specify the proper precision on the Postgre side, even for NUMERIC(precision, scale)
(specifically for the scale
component to ensure it maps to the correct HasResolution
instance).
Yeah, I looked at that issue once and run into trouble myself. I don't recall the specifics, but I recall I wasn't overly pleased with postgres's handling of the numeric type.
Opaleye has a similar discussion going on https://github.com/tomjaguarpaw/haskell-opaleye/issues/230
I personally use Numeric(15,6) to represent money, from what I read Data.Decimal seems like a good choice for a haskell datatype but maybe Fixed could work as well.
None of the instances of
FromField
seem to support themoney
type; is this deliberate or an oversight?It seems as if it should be able to convert to/from
Double
.