Hi, I’m trying to write this query with Ecto but no luck neither with pure Ecto, nor with fragments.
The SQL is:
select * from tbl where (a, b) in (('val11', 'val12'), ('val21', 'val22'))
Here is what I tried (none of the following works):
values1 = [["val11", "val12"], ["val21", "val22"]]
values2 = [{"val11", "val12"},{"val21", "val22"}]
# Ecto funs
from t in Tbl, where: [t.a, t.b] in ^values1
from t in Tbl, where: [t.a, t.b] in ^values2
# fragments
from t in Tbl, where: fragment("(?, ?) in ?", t.a, t.b, ^values1)
from t in Tbl, where: fragment("(?, ?) in ?", t.a, t.b, ^values2)
# even this didn't work
from t in Tbl, where: fragment("(?, ?) in (('val11', 'val12'), ('val21', 'val22'))", t.a, t.b)
I’m now digging so deep into Postgrex.Protocol that I can’t get rid of the feeling I shouldn’t do that and I’m just missing something obvious.