Query Postgres Array field with SQL & ActiveRecord
If you have, for example a string array column in Postgres you can do a query match on any of the array values columns with a SQL query like this:
SELECT * FROM table WHERE 'value' = ANY(str_field);
This will return records where the string ‘value’ is present in at least one of the array string values stored in str_field
Equivalent query in ActiveRecord
ArModel.where("? = ANY(str_field)", "value")
You can also use ALL to match all values in an array column.
Tweet