Sunny Sunny
Sunny Sunny

Reputation: 3230

Concatenating mutiple rows in postgresql into single rows

I have a table containing many rows

I want to all rows of a column to be concatenated to single row

e.g

   columns
  -------
    a
    b
    c
    d
    e

i want to have following result

    a,b,c,d,e

Upvotes: 0

Views: 562

Answers (2)

roman
roman

Reputation: 117571

create table test (a text);

insert into test
values ('a'), ('b'), ('c'), ('d'), ('e');

select string_agg(a, ',') from test

SQL FIDDLE EXAMPLE

Upvotes: 2

Dinup Kandel
Dinup Kandel

Reputation: 2505

SELECT 
array_to_string(array_agg("column"),',') AS yourColumn
FROM Table1

check to see you answer demo

Upvotes: 1

Related Questions