Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
array_agg with distinct works in postgres 9.4 but not in postgres 9.6

I have a query that use array_agg with distinct as an argument and is not accepted on postgres 9.6.

I created this sample to illustrate the issue:

create table numbers (id integer primary key, name varchar(10));
insert into numbers values(1,'one');
insert into numbers values(2,'two');

postgres 9.4

select array_agg(distinct(id)) from numbers;
 array_agg 
-----------
 {1,2}

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.

What do I need to change in order to get this result on postgres 9.6?

Thanks.

This is what I get checking the functions:

nspname | proname | proargtypes 
------------+-----------+--------------------- 
pg_catalog | array_agg | [0:0]={anyarray} 
public | array_agg | [0:0]={anyelement} 
pg_catalog | array_agg | [0:0]={anynonarray

Now, I found the issue thanks to the comment by pozs. I remove the public definition of the aggregated function and it worked.

The issue was just on the database that I was working on, as I found some people saying that the sample worked for them I created a new database an run the example. And then the only change there was the aggregate function definitions.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Now, I found the issue thanks to the comment by pozs. I remove the public definition of the aggregated function and it worked.

The issue was just on the database that I was working on, as I found some people saying that the sample worked for them I created a new database an run the example. And then the only change there was the aggregate function definitions.

So I drop the function public | array_agg | [0:0]={anyelement} and it worked.

Thanks a lot.

over 4 years ago · Santiago Trujillo Relatório

0

It works exactly like that as demonstrated by this dbfiddle on PostgreSQL 9.6.2 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit.

enter image description here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda