Re: [GENERAL] How-To: Aggregate data from multiple rows into a delimited list.

2007-07-03 Thread Dimitri Fontaine
Le lundi 02 juillet 2007, D. Dante Lorenso a écrit : I wanted to select several rows of data and have them returned in a single record with the rows joined by a delimiter. Turns out this is very easy to do in PostgreSQL: SELECT a.id, a.name, ARRAY_TO_STRING(ARRAY( SELECT

Re: [GENERAL] How-To: Aggregate data from multiple rows into a delimited list.

2007-07-03 Thread Pavel Stehule
The query would become SELECT a.id, a.name, array_acc(b.name) as b_names FROM a LEFT JOIN b USING(id) GROUP BY a.id, a.name; All variants are possible. Variant with array_to_string is faster and doesn't need own aggregate function. And you can easy remove duplicities. SELECT a.id, a.name,

[GENERAL] How-To: Aggregate data from multiple rows into a delimited list.

2007-07-02 Thread D. Dante Lorenso
This is not a question, but a solution. I just wanted to share this with others on the list in case it saves you a few hours of searching... I wanted to select several rows of data and have them returned in a single record with the rows joined by a delimiter. Turns out this is very easy to