【发布时间】:2014-09-11 20:34:31
【问题描述】:
来自this tip,我看到我可以搜索具有奇异值的 Postgres 数组,所以:
User.where("'foo@bar.com' = ANY (emails)")
不过,我想知道如何搜索多个值,例如:
User.where("['foo@bar.com', 'bar@foo.com'] = ANY (emails)")
导致PG::SyntaxError
我正在使用 Activerecord 4.1.1
【问题讨论】:
-
你试过
('foo@bar.com', 'bar@foo.com')吗? -
是的,我收到了
ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type record -
试试
where("ANY (emails) IN ('foo@bar.com', 'bar@foo.com'))"或者where("IN ('foo@bar.com', 'bar@foo.com') ANY (emails))" -
:(第一个似乎永远运行直到被中断,没有产生任何结果,而第二个产生
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "IN"
标签: postgresql activerecord sinatra