Rails/Postgres:列必须出现在 group by 子句中

发布于 2024-12-12 00:27:21 字数 575 浏览 0 评论 0原文

所以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗心人 2024-12-19 00:27:21

不,它没有出现。

GROUP BY 包含 date(created_at),而 SELECT 列表仅包含 created_at。如果 created_at 是时间戳,那么这是两个不同的东西。

您需要使用 GROUPY BYcreated_atSELECT date(created_at) (可能是后者)

No, it does not appear.

The GROUP BY contains date(created_at) whereas your SELECT list only contains created_at. If created_at is a timestamp, then these are two different things.

You either need to use GROUPY BY created_at or SELECT date(created_at) (probably the latter)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文