Search code examples
sqlconcatenationpresto

Presto query : concat multiple rows into one string


I have a table: my_table

customer_id
-------------
 2156
 6781
 3145
 1235
 9874

I want the output to be one concat string with comma like: 2156, 6781, 3145, 1235, 9874 So far I export the table and using python to do it. I am wondering could I do it directly in Presto query? Thanks!


Solution

  • I don't think Presto has a string aggregation. Instead, aggregate as an array and convert to a string:

    select array_join(array_agg(customer_id), ', ') as customer_ids
    from my_table