PostgreSQL ilike with multiple matches in Rails ActiveRecord

北城以北 提交于 2021-02-18 06:08:27

问题


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.


回答1:


You can do it by

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


来源:https://stackoverflow.com/questions/26272082/postgresql-ilike-with-multiple-matches-in-rails-activerecord

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!