-
Notifications
You must be signed in to change notification settings - Fork 51
Open
Description
Postgres will parse the time part after the decimal point to a double, then multiply by 1 million, then round to an integer. This can lead to some strange behaviour:
ghci> query conn "select (?)::timestamptz" (Only (UTCTime (fromGregorian 1970 1 1) 0.0000025)) :: IO [Only UTCTime]
[Only {fromOnly = 1970-01-01 00:00:00.000002 UTC}]
That one appears to round down, but this one appears to round up
ghci> query conn "select (?)::timestamptz" (Only (UTCTime (fromGregorian 1970 1 1) 0.5187445)) :: IO [Only UTCTime]
[Only {fromOnly = 1970-01-01 00:00:00.518745 UTC}]
because
ghci> ((0.5187445 :: Double) * (1000000 :: Double))
518744.50000000006
Arguably ToField UTCTime shouldn't exist, since it can't really fit into a timestamptz. But that's probably not an acceptable breaking change so what else could be done about this? Maybe instance ToField UTCTime should truncate to microseconds?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels