I have an array of filters in a ruby application which makes a raw SQL query to a Postgres connection. I'm trying to figure out how I can serialize this array into something query-able,
i.e.: SELECT * FROM data WHERE strings IN #{strings_array}
I can't find any resources for this. What's the correct way to serialize this query?
Edit: I ended up figuring out:
query = ''
arr.each_with_index { |e, i|
if i == arr.length - 1
query += "#{e}"
else
query += "#{e},"
end
}
then
" AND column @> ('{#{query}}')"
But there must be a less verbose way, no?
names = ['Jason', 'Bob', 'Chris']and I want to embednamesinto my query string, so that I can match a columnfirst_nameswhere the values in thenamesarray are in that row