Dhairya Lakhera
Dhairya Lakhera

Reputation: 4818

Concatenate a column from multiple rows into a single formatted string

I have rows like so:

roll_no
---------
0690543
0005331
0760745
0005271

And I want string like this :

"0690543.pdf" "0005331.pdf" "0760745.pdf" "0005271.pdf"

I have tried concat but unable to do so

Upvotes: 1

Views: 1263

Answers (1)

StuartLC
StuartLC

Reputation: 107407

You can use an aggregate function like string_agg, after first mangling the quotes and the .pdf extension to your column data. Use a space as your delimiter:

SELECT string_agg('"'||roll_no||'.pdf "', ' ') from myTable

SqlFiddle here

Upvotes: 1

Related Questions