haskell-beam / haskell-beam/beam

Postgres Int64 "sum_" query throws "Incompatible" exception

Open
#324 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Haskell
Stars
635
Forks
193
PR merge metrics
No merged PRs in 30d

Description

When the type of `_pathQty` is `Int64` (or `Integer`), the following [query](https://github.com/runeksvendsen/beam-sum-fail/blob/0e110a347cd19ea63e302319197a45d778373057/app/Main.hs#L120-L128) fails at runtime with an exception, but works when the type is `Double`.

```haskell
aggregate_
(\path ->
( group_ (_pathSrc path)
, fromMaybe_ 0 (sum_ (_pathQty path))
)
)
(all_ (_paths someDb))
```

Exception thrown:

`PgRowParseError (PgRowCouldNotParseField 1 [Incompatible {errSQLType = "numeric", errSQLTableOid = Nothing, errSQLField = "res1", errHaskellType = "Integer", errMessage = "types incompatible"}])`

There's a minimal example in [this](https://github.com/runeksvendsen/beam-sum-fail/blob/master/app/Main.hs) repo which works when a Postgres docker instance is running using the command `docker run -p 5432:5432 --name postgres-test -e POSTGRES_PASSWORD=test -e POSTGRES_USER=test -e POSTGRES_DB=test -d postgres:9.6`.

Here's the output of the minimal example:

```
CREATE TABLE "paths" ("id" SERIAL UNIQUE NOT NULL, "src" TEXT NOT NULL, "qty" BIGINT NOT NULL, PRIMARY KEY("id"))
INSERT INTO "paths"("id", "src", "qty") VALUES (DEFAULT, 'ABC', 47), (DEFAULT, 'ABC', 3), (DEFAULT, 'ABC', 19), (DEFAULT, 'LOL', 8)
SELECT "t0"."src" AS "res0", COALESCE(SUM("t0"."qty"), 0) AS "res1" FROM "paths" AS "t0" GROUP BY "t0"."src"
DROP TABLE "paths"
example-exe: PgRowParseError (PgRowCouldNotParseField 1 [Incompatible {errSQLType = "numeric", errSQLTableOid = Nothing, errSQLField = "res1", errHaskellType = "Integer", errMessage = "types incompatible"}])
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.