Skip to content

Passing Doubles to val_ sometimes leads to runtime errors #700

@LightAndLight

Description

@LightAndLight

Minimal example:

query ::
  (BeamSqlBackend be, BeamSqlBackendCanSerialize be Int32, BeamSqlBackendCanSerialize be Double) =>
  Q be db s (QExpr be s Int32, QExpr be s Double)
query = pure (val_ 99, val_ 1.0)

...

_ <- runSelectReturningList $ select query

Running this query throws an exception:

BeamRowReadError {brreColumn = Just 1, brreError = ColumnTypeMismatch {ctmHaskellType = "Double", ctmSQLType = "numeric", ctmMessage = "types incompatible"}}

The generated SQL is SELECT 99 AS "res0", 1.0 AS "res1".

Using as_ doesn't helpl, i.e. as_ @Double (val_ 1.0).

The workaround is to use cast_ in a pretty redundant way: cast_ (val_ (1.0 :: Double)) Database.Beam.Query.DataTypes.double. That compiles to the following SQL: SELECT 99 AS "res0", CAST((1.0) AS DOUBLE PRECISION) AS "res1".

I'm surprised that the integer value isn't affected by the same issue.


beam-core version: 0.10.1.0
beam-postgres version: 0.5.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions