Closed mohanzhang closed 8 years ago
I think that today is your lucky day, as this bug may have already been fixed! Can you try using persistent-postgresql-2.2.1
?
Wow, yes. I've spent longer in the checkout line at a grocery store than I did waiting for this fix. Awesome :)
For anyone else reading this, the only change I had to make to my code above was lifting my arrayAgg projection into Maybe
with just
, so:
runDB $ do
select $ from $ \(client `LeftOuterJoin` plan `LeftOuterJoin` consultant) -> do
on (consultant ^. ConsultantId ==. plan ^. PlanConsultantId)
on (plan ^. PlanClientId ==. client ^. ClientId)
groupBy (client ^. ClientId)
return (client, arrayAgg (just $ consultant ^. ConsultantId)) -- <--- note just
Otherwise you will get PersistMarshalError "int64 Expected Integer, received: PersistNull"
, but this makes perfect sense, of course.
Cheers @meteficha!
I'm new to esqueleto (and pretty new to Yesod/Persistent) so I apologize if I'm missing something obvious :) I am getting the following error, and I think I understand why, but I'm not sure how to fix it (from
yesod devel
's log:My query looks like:
The schema is essentially that Clients have many Consultants through Plans, and I am trying to return an array of ConsultantIds for each Client. Since not all Clients have Plans at any given time, it is the case that the consultant ids array may be
{NULL}
. I have verified that the generated SQL looks and works like the SQL I would write by hand, so the marshaling back into haskell types is what is suspect.And as I understand it, this is probably where the error is coming from: Persistent is expecting a list of numbers to marshal, like
{1,2,3}
, but doesn't know what to do with an element ofNULL
. The desired behavior is to have it throw away the null, so that{NULL}
becomes[]
, but I'm not sure how to do this. Is it possible?Thank you for this great library, btw. I have been consistently surprised by how intuitive it has been.