我正在尝试运行如下所示的 sql
select name from appointments where location_id in (2,3,4)
以下不起作用。我正在使用 PostgreSQL
a = [2,3,4]
Appointment.select(:name).where("location_id IN ?", a)
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near "2"
LINE 1: ... FROM "appointments" WHERE (location_id IN 2,3,4)
^
: SELECT name FROM "appointments" WHERE (location_id IN 2,3,4)
最佳答案
你可以使用这个:
Appointment.select(:name).where(:location_id => [2,3,4])
希望对你有帮助
关于ruby-on-rails-3 - 在 rails3 中使用 IN 运算符查找位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6133126/