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

668
Visualizações
Postgres: array_agg throws 'cannot accumulate empty arrays' for empty array(s)

Having problems when using array_agg when a row contains an empty array ({}).

This is my SQL query:

SELECT service_name, metric_name, array_agg(value_textarray)
FROM service_data
WHERE service_name = 'ActivityDataService'
GROUP BY service_name, metric_name

Where the column definitions are the following:

service_name - text
metric_name - text
value_textarray - text[]

When I execute the query and I have empty array ({}) in the database, I get the following error:

ERROR:  cannot accumulate empty arrays

How should I go about fixing this?

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

0

I had the same issue where I couldn't filter the empty array and I found this function. This function avoids the 'accumulating empty arrays' error.

CREATE AGGREGATE array_accum (anyarray)
(
    sfunc = array_cat,
    stype = anyarray,
    initcond = '{}'
);  

source: https://gist.github.com/ryandotsmith/4602274

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