0

Let's say I have a table Foo and has a column name. I want to concatenate all names in Foo. For example

Table Foo

  Name
---------
  name1
  name2
  name3

I want to write a query that returns name1name2name3 or if possible name1,name2,name3.

I have done some googling and see concat function but it only concats columns of same row. I couldn't find a function or a way to accomplish this.

1 Answer 1

3

use string_agg

SELECT string_agg(Foo, ', ') AS col
FROM   tbl
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.