Elixir + Ecto: How to do WHERE NOT IN [array]?

For those who are looking for a "array does not contain any" behaviour.
For example "match_history does not contain device_1 device_2, device_3"

Given you're using PostgreSQL, can use a fragment with the array contains @> operator.

from t in queryable, where: not fragment("? @> ?::varchar[]", t.match_history, ^device_ids)

Or

from t in queryable, where: fragment("NOT ? @> ?::varchar[]", t.match_history, ^device_ids)

Try

User |> where([u], not ^device_id in u.match_history)

Tags:

Elixir

Ecto