PostgreSQL: STRING_AGG() to Concatenate String Per Each Group (Like SQL Server STUFF())

Last week on my Facebook Page, I have received a couple message about what is a similar solution of SQL Server STUFF () in PostgreSQL.

Most of the Database Developers require to perform String Aggregation based on different group of records.

Since PostgreSQL 9.0, STRING_AGG(expression, delimiter) function is available to perform String Aggregation operation.
Using STRING_AGG(), We can concatenate strings using different type of delimiter symbols.

Example of STRING_AGG():

Create a sample Students table:

Insert few sample records:

Concatenate Students Name per each Student Grade and arrange by Grade wise row (Using STRING_AGG()):

The Result:

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from

Leave a Reply

Be the First to Comment!

Notify of