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.)
The GROUP_CONCAT() function in MySQL is used to concatenate data from multiple rows into one field. This is an aggregate (GROUP BY) function which returns a String value, if the group contains at least one non-NULL value. Otherwise, it returns NULL.
The SQL Server Equivalent to GROUP_CONCAT() This function allows you to return a result set as a comma-separated list, as opposed to listing each row as a separate row (as with a normal result set).
Try using this in place of group_concat in Presto ::
select a, array_join(array_agg(b), ',') from table group by a
Also, if you're looking for unique values only – an equivalent to group_concat(distinct ... separator ', ')
– try this:
array_join(array_distinct(array_agg(...)), ', ')
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