combine multiple row values in to one row

From: Lee Harr <missive(at)hotmail(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: combine multiple row values in to one row
Date: 2009-07-06 21:29:35
Message-ID: SNT106-W53280548BAAF282C4E32C1B12B0@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi;

I'm looking for a way to do this:

# \d tbl
Table "public.tbl"
Column | Type | Modifiers
--------+---------+-----------
idn | integer |
code | text |
# SELECT * FROM tbl;
idn | code
-----+------
1 | A
2 | B
2 | C
3 | A
3 | C
3 | E
(6 rows)
# select idn, magic() as codes FROM tbl;
idn | codes
-----+------
1 | A
2 | B, C
3 | A, C, E
(3 rows)

Right now, I use plpgsql functions, but each time I do it
I have to rewrite the function to customize it.

Is there a generic way to do this? An aggregate maybe?

Thanks for any help.

_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John Cheng 2009-07-06 23:17:16 Re: Problem search on text arrays, using the overlaps (&&) operator
Previous Message Paul Smith 2009-07-06 20:39:18 Re: Out of memory error