Oviron Oviron - 6 months ago 28
Ruby Question

Activerecord query against array column using wildcard

So let's say i have a

model with array column
It's pretty easy to find all customers with given phone

Customer.where('? = ANY(phones)', '+79851234567')

But i can't figure out how to use
with wildcard when i want to find customers with phones similar to given one, something like:

Customer.where('ANY(phones) LIKE ?', '+7985%')

I'm using PostgreSQL 9.5 and Rais 4.2

Any ideas?


Can you try this

Customer.where("array_to_string(phones, ', ') like ?", '+7985%')

I believe this will work.