I have an array of record IDs ["303", "430", "4321", "5102"]
. I want to get all records that match these IDs, using SQL:
acceptable_ids = ["303", "430", "4321", "5102"]
@users = User.where("is_awesome = true AND id IN acceptable_ids)
Gives this error:
ActiveRecord::StatementInvalid (PG::SyntaxError: ERROR: syntax error at or near "["
What is the correct way to write my query to get all users with ids that match acceptable_ids
?
Note:
I am aware of User.find(acceptable_ids)
, but can't use this since I am constructing a SQL query with select, where, and join clauses.