beam-postgres 0.5.4.0 → 0.5.4.1
raw patch · 4 files changed
+43/−6 lines, 4 filesdep ~hashablePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: hashable
API changes (from Hackage documentation)
Files
- ChangeLog.md +7/−1
- Database/Beam/Postgres/Syntax.hs +16/−3
- beam-postgres.cabal +1/−1
- test/Database/Beam/Postgres/Test/DataTypes.hs +19/−1
ChangeLog.md view
@@ -1,9 +1,15 @@+# 0.5.4.1++## Bug fixes++ * Fixed an issue where inexact numeric literals (e.g. Haskell type `Double`) were implicitly converted to Postgres `NUMERIC`, triggering a runtime conversion error (#700).+ # 0.5.4.0 ## Added features * Better error messages on column type mismatches (#696).- * Added support for creating and dropping database schemas and associated tables with `createDatabaseSchema`, `dropDatabaseSchema`, `` and `createTableWithSchema` (#716).+ * Added support for creating and dropping database schemas and associated tables with `createDatabaseSchema`, `dropDatabaseSchema`, and `createTableWithSchema` (#716). ## Documentation
Database/Beam/Postgres/Syntax.hs view
@@ -100,7 +100,7 @@ import Data.Aeson (Value, object, (.=)) import Data.Bits import Data.ByteString (ByteString)-import Data.ByteString.Builder (Builder, byteString, char8, toLazyByteString)+import Data.ByteString.Builder (Builder, doubleDec, floatDec, byteString, char8, toLazyByteString) import qualified Data.ByteString.Char8 as B import Data.ByteString.Lazy.Char8 (toStrict) import qualified Data.ByteString.Lazy.Char8 as BL@@ -1202,8 +1202,6 @@ sqlValueSyntax = defaultPgValueSyntax DEFAULT_SQL_SYNTAX(Bool)-DEFAULT_SQL_SYNTAX(Double)-DEFAULT_SQL_SYNTAX(Float) DEFAULT_SQL_SYNTAX(Int8) DEFAULT_SQL_SYNTAX(Int16) DEFAULT_SQL_SYNTAX(Int32)@@ -1230,6 +1228,21 @@ DEFAULT_SQL_SYNTAX(Pg.LocalTimestamp) DEFAULT_SQL_SYNTAX(Pg.UTCTimestamp) DEFAULT_SQL_SYNTAX(Scientific)++-- We have a 'manual' instance for Double and Float because the default value of a+-- literal like "1.0" is NUMERIC, not DOUBLE. However, NUMERIC values are exact, +-- while DOUBLEs are inexact. This means that converting from SQL NUMERIC+-- to Haskell Double is lossy.+-- See #700+instance HasSqlValueSyntax PgValueSyntax Float where+ sqlValueSyntax v + | isNaN v || isInfinite v = PgValueSyntax $ emit "'" <> emitBuilder (floatDec v) <> emit "'"+ | otherwise = PgValueSyntax $ emit "'" <> emitBuilder (floatDec v) <> emit "'::double precision"++instance HasSqlValueSyntax PgValueSyntax Double where+ sqlValueSyntax v + | isNaN v || isInfinite v = PgValueSyntax $ emit "'" <> emitBuilder (doubleDec v) <> emit "'"+ | otherwise = PgValueSyntax $ emit "'" <> emitBuilder (doubleDec v) <> emit "'::double precision" instance HasSqlValueSyntax PgValueSyntax (CI T.Text) where sqlValueSyntax = sqlValueSyntax . CI.original
beam-postgres.cabal view
@@ -1,5 +1,5 @@ name: beam-postgres-version: 0.5.4.0+version: 0.5.4.1 synopsis: Connection layer between beam and postgres description: Beam driver for <https://www.postgresql.org/ PostgreSQL>, an advanced open-source RDBMS homepage: https://haskell-beam.github.io/beam/user-guide/backends/beam-postgres
test/Database/Beam/Postgres/Test/DataTypes.hs view
@@ -21,7 +21,8 @@ tests postgresConn = testGroup "Data-type unit tests" [ jsonNulTest postgresConn- , errorOnSchemaMismatch postgresConn ]+ , errorOnSchemaMismatch postgresConn+ , errorOnLiteralDoubles postgresConn ] data JsonT f = JsonT@@ -136,3 +137,20 @@ assertBool "runInsertReturningList succeeded" didFail didFail @?= True++-- | Regression test for <https://github.com/haskell-beam/beam/issues/700>+errorOnLiteralDoubles :: IO ByteString -> TestTree+errorOnLiteralDoubles pgConn =+ testCase "Literal `Double`s are correctly specified as SQL `DOUBLE` (#700)" $ + withTestPostgres "db_failures" pgConn $ \conn -> do+ results <- runBeamPostgres conn $ + runSelectReturningList $ + select $ + query+ + results @?= [(99 :: Int32, 1.0 :: Double)]+ + where+ -- We need to provide a db for type-checking, but it will not be used+ query :: Q Postgres RealDb s (QExpr Postgres s Int32, QExpr Postgres s Double)+ query = pure (val_ 99, val_ 1.0)