ERROR: WITHIN GROUP is required for ordered-set aggregate mode

问题描述 投票:0回答:1

我一直在使用具有此功能的 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';

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

sql postgresql aggregate-functions
1个回答
10
投票

Postgres 9.4 引入了聚合函数的新子类。 说明书:

有一个集合函数的子类叫做 ordered-set order_by_clause

required的聚合,通常是因为
聚合的计算仅在特定的情况下才有意义
输入行的排序。

一个新的内置有序集聚合函数是

mode()
,它恰好与您的自定义聚合函数的名称冲突。 (您所指的 Postgres Wiki 页面 自 2013 年以来就没有更新过。)

解决方案

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

© www.soinside.com 2019 - 2024. All rights reserved.