PostgreSQL ilike with multiple matches in Rails ActiveRecord

I am trying to retrieve several records from my database with the following query:

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

this works great. Now I want to get several records at the same time and tried this (which seems syntactically wrong):

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

What am I doing wrong?

So, just to clarify: I want to get all the records corresponding to one of the names, so its the OR query I'm looking for.

+6
source share
1 answer

You can do it with

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

Source: https://habr.com/ru/post/976473/


All Articles