PostgreSQL ilike 在 Rails ActiveRecord 中有多个匹配项 [英] PostgreSQL ilike with multiple matches in Rails ActiveRecord

查看:56
本文介绍了PostgreSQL ilike 在 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%'])

我做错了什么?

所以只是为了澄清:我想检索与其中一个名称匹配的所有记录,因此它是我正在寻找的 OR 语句.

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.

推荐答案

你可以通过

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

这篇关于PostgreSQL ilike 在 Rails ActiveRecord 中有多个匹配项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆