Ruby Rails - 按日期月份查询

Ruby Rails - Query by Date Month

我想 select 游戏 table 中日期列中有一个月份大于 6 的条目的所有条目。游戏 table 的列是 date_column、id、winning_side、状态、away_score、home_score。数据库是 Postgres。像

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

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

对 'month' 参数使用引号:

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

您需要用单引号将月份这个词括起来,即

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