我试图写一些条件来从数据库中提取对象:
Page.where(published: true).where("`published_at` <= current_date()").where("`publication_end` IS NULL OR `publication_end` > current_date()")
当我在rails控制台中输入它时出现以下错误:
SELECT "pages".* FROM "pages" WHERE "pages"."published" = 't' AND (`published_at` <= current_date()) AND (`publication_end` IS NULL OR `publication_end` > current_date())
PG::SyntaxError: ERROR: syntax error at or near "("
LINE 1: ...blished" = 't' AND (`published_at` <= current_date()) AND (`...
^
: SELECT "pages".* FROM "pages" WHERE "pages"."published" = 't' AND (`published_at` <= current_date()) AND (`publication_end` IS NULL OR `publication_end` > current_date())
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "("
LINE 1: ...blished" = 't' AND (`published_at` <= current_date()) AND (`...
^
: SELECT "pages".* FROM "pages" WHERE "pages"."published" = 't' AND (`published_at` <= current_date()) AND (`publication_end` IS NULL OR `publication_end` > current_date())
我,使用Postgresql 请帮忙。
答案 0 :(得分:2)
删除括号:
# select current_date();
ERROR: syntax error at or near "("
LINE 1: select current_date();
# select current_date;
date
------------
2014-02-19
(1 row)
答案 1 :(得分:-1)
Page.where(published: true).where("published_at <= current_date").where("publication_end IS NULL OR publication_end > current_date")
现在我确定
谢谢:)