我必须从User
模型中查找所有包含子字符串“ cpg”的电子邮件。因此它将匹配“ [email protected]”,“ [email protected]”等
我很确定如何区分大小写(使用,User.where("lower(email)...")
但我不知道如何找到子字符串。
我正在使用Rails 3 + Postgres 9.x
在Rails中什么也做不了,您只能使用PostgreSQL的ilike
(不区分大小写的函数)。
像这样: User.where("email ilike '%cpg%'")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句