Bro*_*_80 6 postgresql postgresql-9.4 array-agg postgresql-9.6
我有一个查询,它使用带有 distinct 作为参数的 array_agg 并且在 postgres 9.6 上不被接受。
我创建了这个示例来说明这个问题:
create table numbers (id integer primary key, name varchar(10));
insert into numbers values(1,'one');
insert into numbers values(2,'two');
Run Code Online (Sandbox Code Playgroud)
postgres 9.4
select array_agg(distinct(id)) from numbers;
array_agg
-----------
{1,2}
Run Code Online (Sandbox Code Playgroud)
postgres 9.6
ERROR: function array_agg(integer) is not unique
LINE 1: select array_agg(distinct(id)) from numbers;
^
HINT: Could not choose a best candidate function.
You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)
为了在 postgres 9.6 上获得这个结果,我需要改变什么?
谢谢。
这是我检查功能的结果:
nspname | proname | proargtypes
------------+-----------+---------------------
pg_catalog | array_agg | [0:0]={anyarray}
public | array_agg | [0:0]={anyelement}
pg_catalog | array_agg | [0:0]={anynonarray
Run Code Online (Sandbox Code Playgroud)
现在,由于pozs的评论,我发现了这个问题。我删除了聚合函数的公共定义并且它起作用了。
问题仅出在我正在处理的数据库上,因为我发现有些人说该示例对他们有用,因此我创建了一个新数据库并运行该示例。然后唯一的变化是聚合函数定义。
现在,由于 pozs 的评论,我发现了这个问题。我删除了聚合函数的公共定义并且它起作用了。
问题仅出在我正在处理的数据库上,因为我发现有些人说该示例对他们有用,因此我创建了一个新数据库并运行该示例。然后唯一的变化是聚合函数定义。
所以我删除了函数 public | array_agg | [0:0]={anyelement} 并且它起作用了。
非常感谢。
它的工作原理与 x86_64-pc-linux-gnu 上的 PostgreSQL 9.6.2 上的 dbfiddle 所演示的完全相同,由 gcc (Debian 4.9.2-10) 4.9.2, 64-bit 编译。