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:
CREATE TABLE tbl_Students
,StudName CHARACTER VARYING
Insert few sample records:
INSERT INTO tbl_Students
Concatenate Students Name per each Student Grade and arrange by Grade wise row (Using STRING_AGG()):
,STRING_AGG(StudName,', ') AS StudPerGrade
GROUP BY StudGrades
ORDER BY 1 ;
studgrades | studpergrade
A | Anvesh, Sofia
B | Kimly, Ali
C | Jenny, Roy, Martin
D | Mukesh
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 dbrnd.com, 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.