-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coalesceDefault [arrayAgg x] (val [])
causes a malformed array literal
#355
Comments
Yeah, this is a really unfortunate issue with the |
Hi everyone, I'm having the same issue. Is there any workaround at the moment? (using unsafe function or write custom types) |
I found a workaround, we can use mkPostgresArray :: Show a => [a] -> SqlExpr (Value b)
mkPostgresArray list =
let rawValue = "'{" <> Text.intercalate ", " ((Text.pack . show) <$> list) <> "}'"
in unsafeSqlValue $ TLB.fromText rawValue
query bIds =
...
having (
(arrayAggWith AggModeDistinct
(a ^. ABId)
[asc (a ^. ABId)])
==. mkPostgresArray (List.sort bIds)
) |
You almost certainly don't want You may need to handle the empty list case separately, as well |
I'm writing a query using
arrayAgg
, which can return aNULL
/Nothing
value, so I'm combining it withcoalesceDefault
to just get an empty array in that case. E.g.:But executing this throws an exception saying the query has a malformed array literal:
On the other hand, if I omit the coalesce:
Then I get the expected result of
[Value {unValue = Just [1,2,3]}]
My guess is that the error happens because the faulty query uses the
PersistField [a]
instance, which serialises the literal as aPersistList
instead of aPersistArray
. PerhapsarrayAgg
shouldn't return a plain list but use the (currently private)PostgresArray
frompersistent-postgresql
.The text was updated successfully, but these errors were encountered: