thiagomajesk
Ecto coalesce query translating to empty object, is this a bug?
Hi! While working with JSON data the other day, I noticed that coalesce(q.field, []) is being translated to coalesce(f0."o", '{}') instead of coalesce(f0."o", '[]'), which is kinda annoying because the former will result in an empty map and not an empty list like the later.
I thought this was related to JSON specifically, but I managed to create a small repro and it seems there’s something here that I’m not aware of:
Repo.all(from x in fragment("select null AS o"), select: coalesce(x.o, []))
Do you guys have any idea why this is translated to the query bellow?
SELECT coalesce(f0."o", '{}') FROM (select null AS o) AS f0 []
In the meantime, I’m just specifying the proper coalesce clause as a fragment: fragment("COALESCE(?, '[]')", q.field), but it feels this should be supported!?
Most Liked
LostKobrakai
Postgres has a native array type. If you want json you need to typecast to json where ecto cannot infer that it‘s dealing with json.








