2

How do I concatenate ARRAYS of different sizes ? Tried :

 select array_agg(field) from table

but I'm getting this :

ERROR: cannot accumulate arrays of different dimensionality

table:

field
-----
{1,2,3}
{3,8}
{9,0,7,9,6}
{4}
...

expected result:

{1,2,3,3,8,9,0,7,9,6,4}
sten
  • 7,028
  • 9
  • 41
  • 63
  • 1
    If you want to *concatenate* them, don't use `array_agg`, which tries to put them into a multidimensional array. – Bergi May 21 '21 at 21:23
  • 1
    What data type is `field`, what do your values look like (an example table), and what result do you expect? – Bergi May 21 '21 at 21:26
  • 1
    please provide sample data and desired output and a clear explaination – eshirvana May 22 '21 at 01:34

1 Answers1

0

Found the answer to my question :

PostgreSQL array_agg(INTEGER[])

CREATE AGGREGATE array_concat_agg(anyarray) (
  SFUNC = array_cat,
  STYPE = anyarray
);

from : Łukasz Kamiński

sten
  • 7,028
  • 9
  • 41
  • 63