我正在尝试运行下面这样的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])
希望这能帮助
我不知道rails,但在我看来,你需要这样做:
Appointment.select(:name).where("location_id IN (?)", a)
即在CCD_ 2周围放置括号。