Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a listagg on Redshift?

For sample data as below,

Col1 Col2
1    A
1    B
1    C
2    A
2    B

the output I am looking for is

COL1 COL2
1    A B C
2    A B

This can be done using LISTAGG on Oracle or recursive queries on other DBs but Redshift doesnt support both.

How do I achieve this on Redshift

like image 933
Raniendu Singh Avatar asked Sep 16 '25 05:09

Raniendu Singh


1 Answers

They just added LISTAGG() to Redshift (2015-07-31). http://docs.aws.amazon.com/redshift/latest/dg/r_LISTAGG.html

like image 152
Joe Harris Avatar answered Sep 17 '25 19:09

Joe Harris