Skip to content

Literal expressions fail to parse when returned from Postgres query #348

Open
@ollef

Description

@ollef

Hey again!

Running this:

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:

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions