Rails/Postgres:列必须出现在 group by 子句中
所以 Postgres 正在抱怨:
PGError: ERROR: column "sessions.created_at" must appear in the GROUP BY clause or be used in an aggregate function
但问题是,“created_at”确实出现在 group by 子句中:
SELECT created_at, count(id) as visit_count FROM "sessions" WHERE ("sessions"."site_id" IN (4, 3)) AND ("sessions"."created_at" >= '2011-10-20 00:00:00.000000') AND ("sessions"."created_at" <= '2011-10-27 23:59:59.999999') GROUP BY date(created_at))
它可能与被包装在 date() 中的created_at 有关吗?
提前致谢!
So Postgres is complaining about:
PGError: ERROR: column "sessions.created_at" must appear in the GROUP BY clause or be used in an aggregate function
But the trouble is, "created_at" does appear in the group by clause:
SELECT created_at, count(id) as visit_count FROM "sessions" WHERE ("sessions"."site_id" IN (4, 3)) AND ("sessions"."created_at" >= '2011-10-20 00:00:00.000000') AND ("sessions"."created_at" <= '2011-10-27 23:59:59.999999') GROUP BY date(created_at))
Does it have something to do with created_at being wrapped in date() perhaps?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,它没有出现。
GROUP BY 包含
date(created_at)
,而 SELECT 列表仅包含created_at
。如果created_at
是时间戳,那么这是两个不同的东西。您需要使用
GROUPY BYcreated_at
或SELECT date(created_at)
(可能是后者)No, it does not appear.
The GROUP BY contains
date(created_at)
whereas your SELECT list only containscreated_at
. Ifcreated_at
is a timestamp, then these are two different things.You either need to use
GROUPY BY created_at
orSELECT date(created_at)
(probably the latter)