我曾经有过这样的查询:
MyModel.where(id: ids)
生成sql查询,如:
SELECT "my_models".* FROM "my_models"
WHERE "my_models"."id" IN (1, 28, 7, 8, 12)
现在,我想将其更改为ANY而不是IN。我创建了这个:
MyModel.where("id = ANY(VALUES(#{ids.join '),('}))"
现在,当我使用空数组时ids = [],出现以下错误:
MyModel Load (53.0ms) SELECT "my_models".* FROM "my_models" WHERE (id = ANY(VALUES()))
ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
ActiveRecord::StatementInvalid: ActiveRecord::JDBCError: org.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
Position: 75: SELECT "social_messages".* FROM "social_messages" WHERE (id = ANY(VALUES()))
from arjdbc/jdbc/RubyJdbcConnection.java:838:in `execute_query'
白板的微信
慕虎7371278
慕少森
相关分类