“(”附近的Postgresql语法错误

时间:2014-02-19 15:52:14

标签: ruby-on-rails postgresql ruby-on-rails-4 ruby-on-rails-3.2

我试图写一些条件来从数据库中提取对象:

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 请帮忙。

2 个答案:

答案 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")

现在我确定

谢谢:)