Hi there,
I recently migrated parts of my data to Elasticsearch to improve performance. Now, I need to select a list of entries from a table using Ecto. Each entry is uniquely identified by two attributes: user_id
and auction_id
.
In raw SQL, the query works perfectly:
It works perfectly fine in SQL:
SELECT * FROM table WHERE (table.user_id, table.auction_id) in ((1,2), (3,4)...)
However, I’m struggling to replicate this in Ecto. I’ve tried preparing the list as tuples:
list = [{1, 2}, {3, 4}]
from(t in Table, where: {t.user_id, t.auction_id} in ^list
I’ve also tried using a list of lists (each with two elements):
list = [[1, 2], [3, 4]]
from(t in Table, where: {t.user_id, t.auction_id} in ^list
Unfortunately, neither approach works.
Is there a way to achieve this in Ecto without resorting to raw SQL? Falling back to raw SQL feels like a less-than-ideal solution.
I’d appreciate any suggestions or insights!