haskell-beam / haskell-beam/beam

Literal expressions fail to parse when returned from Postgres query

Open
#348 5 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

Hey again!

Running this:

```haskell
import Database.Beam
import Database.Beam.Postgres
import Database.Beam.Postgres.Syntax
import Data.Text (Text)

test :: Connection -> IO ()
test conn = do
let
t :: QExpr PgExpressionSyntax s Text
t = "abc"

result <- withDatabaseDebug putStrLn conn (runSelectReturningOne (select (pure t)) :: Pg (Maybe Text))
print result
```

results in:

```sql
SELECT 'abc' AS "res0"
testapp: PgRowParseError (PgRowCouldNotParseField 0)
```

It seems like the error can be fixed by casting the value to the right type, i.e. by making the query `SELECT ('abc'::text) AS "res0"`. I suppose the parser (which might be inherited from postgres-simple?) is strict about what types it allows whereas the printer outputs string literals which have unknown type until you cast them (`pg_typeof('abc')` is `unknown`).

Several (most?) other types also have this problem.

Cheers!

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.