Ruby Rails - 按日期查询

时间:2015-09-16 15:38:46

标签: sql ruby-on-rails ruby where

我想选择Game表中的所有条目,其中date列有一个月份大于6的条目.Game表的列是date_column,id,winning_side,status,away_score,home_score。 DB是Postgres。像

这样的东西
Game.where("date_part(month, date_column) > ?", 6)

date_part似乎是正确的SQL函数,但这是失败的。

2 个答案:

答案 0 :(得分:3)

使用'月'参数:

Game.where("date_part('month', date_column) > ?", 6)

答案 1 :(得分:2)

您需要用单引号括住单词month,即

Game.where("date_part('month', date_column) > ?", 6)