You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sum_'s type is (PersistField a, PersistField b) => expr (Value a) -> expr (Value (Maybe b)). But sum of course cannot return any type. In Postgres, it returns numeric for bigints, which is represented as PersistRational. Details here. Example:
moduleMainwhereimportControl.Monad.IO.ClassimportControl.Monad.LoggerimportDatabase.EsqueletoimportDatabase.PersistimportDatabase.Persist.PostgresqlimportDatabase.Persist.TH
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
Number
value Int
|]
connStr ="host=localhost dbname=test user=test password=test port=5432"main::IO()
main = runStderrLoggingT $ withPostgresqlPool connStr 10$\pool -> liftIO $doflip runSqlPersistMPool pool $do
runMigration migrateAll
johnId <- insert $Number5
janeId <- insert $Number22return()
_ :: [Value (MaybeInt)] <- select $
from $\number ->doreturn$ sum_ $ number ^.NumberValuereturn()
enolan at behemoth in ~/junk/esqueleto-bug
$ stack exec esqueleto-bug
[Debug#SQL] INSERT INTO "number"("value") VALUES(?) RETURNING "id"; [PersistInt64 5]
[Debug#SQL] INSERT INTO "number"("value") VALUES(?) RETURNING "id"; [PersistInt64 22]
[Debug#SQL] SELECT SUM("number"."value")
FROM "number"
; []
esqueleto-bug: PersistMarshalError "int Expected Integer, received: PersistRational (27 % 1)"
I suppose it needs a type family/fundep. Test case repo here.
The text was updated successfully, but these errors were encountered:
sum_
's type is(PersistField a, PersistField b) => expr (Value a) -> expr (Value (Maybe b))
. But sum of course cannot return any type. In Postgres, it returnsnumeric
forbigint
s, which is represented asPersistRational
. Details here. Example:I suppose it needs a type family/fundep. Test case repo here.
The text was updated successfully, but these errors were encountered: