sqlite-simple
sqlite-simple copied to clipboard
Convert NULLs to NaN for Double/Floats
SQLite stores NaN as NULL so we convert them back as NaN. Small program to illustrate issue.
go = withConnection ":memory:" $ \h -> do
execute_ h "CREATE TABLE foo (x REAL)"
execute h "INSERT INTO foo VALUES (?)" (Only (1::Double))
execute h "INSERT INTO foo VALUES (?)" (Only ((0/0)::Double))
mapM_ print =<< (query_ h "SELECT * FROM foo" :: IO [Only (Maybe Double)])
mapM_ print =<< (query_ h "SELECT * FROM foo" :: IO [Only Double])
Output
*Main> go
Only {fromOnly = Just 1.0}
Only {fromOnly = Nothing}
*** Exception: ConversionFailed {errSQLType = "NULL", errHaskellType = "Double", errMessage = "expecting an SQLFloat column type"}
SQLite using same representation for NaN and NULL could cause some troubles. It makes impossible to distinguish between Just NaN
and Nothing
. So I'm not sure it is right thing to do.