I have a table conditions
with a trigger_values
column that is of type array and I want to query this table on the trigger_values and fetch the matching records.
For example, suppose my conditions table has 3 rows:
<Condition id: 1, trigger_values: [1, 2, 3]>,
<Condition id: 2, trigger_values: [2, 4]>,
<Condition id: 3, trigger_values: [3, 5, 7]>
and I have the query parameter 3
, I should get conditions 1 and 3 as their trigger_values columns contain 3
.
Basically, I want something like this:
Condition.where('trigger_values CONTAINS ?', query_value)
Any help would be appreciated. Thanks
CodePudding user response:
You should use the IN
operator:
Condition.where('trigger_values IN (?)', query_value)
CodePudding user response:
Found the solution:
Condition.where("'#{query_value}' = ANY(trigger_values)")
I needed to use ANY command.