Alex Herman
Alex Herman

Reputation: 2848

PostgreSQL - join multiple lines from one column into one string in SELECT query

I'm trying to join all results from one column in SELECT query into one string.

Some of you might be familiar with C#:

string.Join(separator, stringArray)

The following statement doesn't return all results as one string

SELECT CONCAT(text) FROM orders

Does anyone have an idea of how to replicate that C# code by means of SQL?

Upvotes: 1

Views: 2501

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271231

You are looking for string_agg():

select string_agg(text separator, ',')
from orders;

Upvotes: 2

Related Questions