Severin
Severin

Reputation: 8588

PostgreSQL ilike with multiple matches in Rails ActiveRecord

I am trying to retrieve multiple records from my DB with the following query:

User.where('name ilike ?','%thomas%')

this works fine. Now I want to retrieve multiple records at the same time and tried this (which seems to be syntactically incorrect):

User.where('name ilike any',['%thomas%','%james%','%martin%'])

What am I doing wrong?

So just to clarify: I want to retrieve all records that match one of the names, so its an OR statement I am looking for.

Upvotes: 10

Views: 7427

Answers (1)

Debadatt
Debadatt

Reputation: 6015

You can do it by

User.where('name ilike any ( array[?] )',['%thomas%','%james%','%martin%'])

Upvotes: 34

Related Questions