在Rails查询上获取数据库错误

时间:2012-04-29 23:49:39

标签: ruby-on-rails-3 postgresql

我正在尝试使用rake任务在PostgreSQL中查询错误。

  posts = Post.where("status IS ? AND publish_on < ?", 'queued', Time.now)

这是错误:

PGError: ERROR:  syntax error at or near "'queued'"
    LINE 1: SELECT "posts".* FROM "posts"  WHERE (status IS 'queued' AND...
                                                            ^
    : SELECT "posts".* FROM "posts"  WHERE (status IS 'queued' AND publish_on < '2012-04-29 23:44:06.423516')

起初我认为这是引用,但改变它们并不起作用。现在我认为我是如何同意和条款的?

1 个答案:

答案 0 :(得分:2)

IS仅用于与TRUEFALSENULL进行比较。您可能需要=代替:

posts = Post.where("status = ? AND publish_on < ?", 'queued', Time.now)