gpt4 book ai didi

postgresql - 错误 : WITHIN GROUP is required for ordered-set aggregate mode

转载 作者:行者123 更新时间:2023-11-29 11:59:43 27 4
gpt4 key购买 nike

我一直在使用具有此功能的 Postgres(版本 9.2 和 9.3):https://wiki.postgresql.org/wiki/Aggregate_Mode一阵子。最近升级到 9.4 版本后,我在使用该功能时遇到以下错误:

PG::WrongObjectType: ERROR:  WITHIN GROUP is required for ordered-set aggregate mode
LINE 1: SELECT mode(logins_count) AS mode_value FROM "registrations" WHERE "registrations"."cr...

在做的时候出现错误:

SELECT mode(logins_count) AS mode_value FROM registrations
WHERE registrations.created_at > '20141105';

我不明白错误消息,也不知道我需要更改什么?

最佳答案

Postgres 9.4 引入了聚合函数的新子类。 Per documentation:

There is a subclass of aggregate functions called ordered-set aggregates for which an order_by_clause is required, usually because the aggregate's computation is only sensible in terms of a specific ordering of its input rows.

其中一个新的内置有序集合聚合函数是 mode()这恰好与您的自定义聚合函数的名称发生冲突。 (您所指的 Postgres Wiki page 自 2013 年以来一直未更新。)

解决方案

为您的自定义聚合函数使用不同的名称以避免冲突。
或者更好:改用新的内置函数。阅读 updated Postgres Wiki了解详情。

关于postgresql - 错误 : WITHIN GROUP is required for ordered-set aggregate mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31031039/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com