I am facing an issues creating a query to exclude results if a jsonb array field contains specified value.
This works in plain sql and I am trying to generate it from Ecto:
If I run plain sql it works though:
AND (not o0.“exclusions” @> ‘[83055]’)
I tried more ideas including this two:
where: fragment(“not ? @> ‘[?]’”, c.exclusions, ^dish_id)
It generates this sql:
(not o0.“exclusions” @> ‘[$2]’)
This does not run:
** (Postgrex.Error) ERROR 22P02 (invalid_text_representation): invalid input syntax for type json
value = “‘[#{dish_id}]’”
where: fragment(“not ? @> ?”, c.exclusions, ^value)
This generates:
(not o0.“exclusions” @> $2) [10318, “‘[83055]’”]
It does not raise any error but the filter is not working.