I can create an array of arrays:
select array[array[1, 2], array[3, 4]];
array
---------------
{{1,2},{3,4}}
But I can't aggregated arrays:
select array_agg(array[c1, c2])
from (
values (1, 2), (3, 4)
) s(c1, c2);
ERROR: could not find array type for data type integer[]
What am I missing?
I use:
CREATE AGGREGATE array_agg_mult(anyarray) (
SFUNC = array_cat,
STYPE = anyarray,
INITCOND = '{}'
);
and queries like:
SELECT array_agg_mult( ARRAY[[x,x]] ) FROM generate_series(1,10) x;
Note that you must aggregate 2-dimensional arrays, so you'll often want to wrap an input array in a single-element ARRAY[array_to_aggregate]
array constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With