Alex
Alex

Reputation: 11579

`string_agg` in postgresql maximum length

For example, the function string_agg(name,',') returns abc,d,e,f,g.
Is there any way to set maximum length for the function string_agg to return only first N characters abc,d,e,... or ab...?
P.S. No matter how it will be splitted.

Upvotes: 0

Views: 2106

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

You can just take the first "n" characters after doing the aggregation:

select left(string_agg(name, ','), N) as FirstN

Upvotes: 1

Related Questions