I have a table with two columns: k is the key, and a may contain null values. An example is as follows:
drop table if exists test;
create table test(k, a) as
select * from ( values
(1, 1),
(2, 2),
(3, 3),
(4, NULL),
(5, NULL),
(6, 6),
(7, 7),
(8, NULL),
(9, 9),
(10, 10)
) t;
I would need to aggregate the values of column a ordered by column k into several arrays without null values. Using array_agg and filter is NOT what I need
select array_agg(a order by k) from test
-- "{1,2,3,NULL,NULL,6,7,NULL,9,10}"
select array_agg(a order by k) filter (where a is not null) from test
-- "{1,2,3,6,7,9,10}"
What I need to obtain is as follows
"{1,2,3}"
"{6,7}"
"{9,10}"
Any idea how to achieve this ?