You want the PostgreSQL array-overlaps or array-contained-by operators, depending on whether you want AND or OR-like behaviour.
SELECT ARRAY['[email protected]', '[email protected]'] @@ emails FROM ...
or
SELECT ARRAY['[email protected]', '[email protected]'] <@ emails FROM ...
Making Rails emit PostgreSQL array literals is hopefully fairly easy, but beyond my Rails-fu of nearly nil.
If emails is of type varchar[] instead of text[] then you need to cast the array literal to varchar too, e.g.
SELECT ARRAY['[email protected]', '[email protected]']::varchar[] <@ emails FROM ...
To test out the functionality stand-alone, you can just evaluate standalone expressions, e.g.
regress=> SELECT ARRAY['[email protected]', '[email protected]'] <@ ARRAY['[email protected]', '[email protected]', 'fred'];
?column?
----------
t
(1 row)
('[email protected]', '[email protected]')?ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type recordwhere("ANY (emails) IN ('[email protected]', '[email protected]'))"or thenwhere("IN ('[email protected]', '[email protected]') ANY (emails))"ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "IN"