How to Group by and concatenate arrays in PostgreSQL
I have a table in PostgreSQL. I want to concatenate all the arrays(i.e. col) after grouping them by time. The arrays are of varying dimensions. | time | col | |------ |------------------ | | 1 | {1,2} | | 1 | {3,4,5,6} | | 2 | {} | | 2 | {7} | | 2 | {8,9,10} | | 3 | {11,12,13,14,15} | The result should be as follows: | time | col | |------ |------------------ | | 1 | {1,2,3,4,5,6} | | 2 | {7,8,9,10} | | 3 | {11,12,13,14,15} | What I have come up with so far is as follows: SELECT ARRAY(SELECT elem FROM tab, unnest(col) elem); But this does not do the grouping. It just takes the entire table and
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.