Sequel, pass value to pg_array query

399 Views Asked by At

I am looking for a way to pass an array param to a pg_array query (https://www.postgresql.org/docs/8.2/static/functions-array.html). Something like:

Model.where("array_col && ?", ids)

&& - overlap

ids = [2,3]

array_col is array containing integers for example [1,2]

When hardcoded works:

Model.where("array_col && ARRAY[2,3]")
1

There are 1 best solutions below

0
On BEST ANSWER

Load the pg_array extension into the Sequel::Database object (it ships with Sequel), then:

Model.where("array_col && ?", Sequel.pg_array(ids))

Sequel also ships with a pg_array_ops extension, which allows you to do:

Model.where(Sequel.pg_array(:array_col).overlaps(ids))