How do I concatenate row-wise instead of column-wise? - Mailing list pgsql-sql

From Marcus Claesson
Subject How do I concatenate row-wise instead of column-wise?
Date
Msg-id 3D33D4AA.1020600@angiogenetics.se
Whole thread Raw
Responses Re: How do I concatenate row-wise instead of column-wise?  (Richard Huxton <dev@archonet.com>)
Re: How do I concatenate row-wise instead of column-wise?  ("Rajesh Kumar Mallah." <mallah@trade-india.com>)
List pgsql-sql
I have a table like this:
SELECT * FROM old_tab;
id    |    descr   
-------------------
1    |    aaa
1    |    aaa
1    |    bbb
2    |    ccc
2    |    bbb   
3    |    ddd   
3    |    ddd
3    |    eee
3    |    fff
4    |    bbb
etc...

And I want a new table where the descr is concatenated row-wise like this:
SELECT * FROM new_tab;
id    |    descr   
--------------------------
1    |    aaa;bbb
2    |    ccc;bbb
3    |    ddd;eee;fff
4    |    bbb
etc...

This is the closest I get....:
UPDATE new_tab SET descr = old_tab.descr||' ; '||old_tab.descr from 
old_tab where old_tab.id=new_tab.id;
UPDATE 4
SELECT * FROM new_tab ;id |   descr  
----+-----------1  | aaa ; aaa2  | ccc ; ccc3  | ddd ; ddd4  | bbb ; bbb
etc...

Thus, the concatenating operator never works on other rows than the 
present. How can I get around that and still stick to the postgresql syntax?

Regards
Marcus




pgsql-sql by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: line datatype
Next
From: "Luis Alberto Amigo Navarro"
Date:
Subject: Re: [HACKERS] please help on query