Presto equivalent of MySQL group_concat

Mike Moyer picture Mike Moyer · May 23, 2017 · Viewed 23.5k times · Source

I'm new to Presto and looking to get the same functionality as the group_concat function in MySQL. Are the following two equivalent? If not, any suggestions for how I can recreate the group_concat functionality in Presto?

MySQL:

select 
  a,
  group_concat(b separator ',')
from table
group by a

Presto:

select 
  a,
  array_join(array_agg(b), ',')
from table
group by a

(Found this as a suggested Presto workaround here when searching group_concat functionality.)

Answer

Rahul Ahuja picture Rahul Ahuja · Feb 24, 2018

Try using this in place of group_concat in Presto ::

select 
  a,
  array_join(array_agg(b), ',')
from table
group by a