Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 855
Severin Avatar asked Oct 09 '14 06:10

Severin


1 Answers

You can do it by

User.where('name ilike any ( array[?] )',['%thomas%','%james%','%martin%'])
like image 105
Debadatt Avatar answered Nov 08 '22 23:11

Debadatt