From: | David Fetter <david(at)fetter(dot)org> |
---|---|
To: | Lee Harr <missive(at)hotmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: combine multiple row values in to one row |
Date: | 2009-07-07 15:43:04 |
Message-ID: | 20090707154304.GJ32215@fetter.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Tue, Jul 07, 2009 at 08:40:06AM -0700, David Fetter wrote:
> On Tue, Jul 07, 2009 at 01:59:35AM +0430, Lee Harr wrote:
> >
> > Is there a generic way to do this? An aggregate maybe?
>
> The aggregate is called array_agg() and it's in 8.4. You can then
> wrap array_to_string() around it and get pretty formatting, as in:
>
> SELECT idn, array_to_string(array_agg(code),', ') AS codes FROM tbl;
Oops. That should read:
SELECT
idn,
array_to_string(array_agg(code),', ') AS codes
FROM tbl
GROUP BY idn; /* gotta group by :) */
Cheers,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter
Skype: davidfetter XMPP: david(dot)fetter(at)gmail(dot)com
Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate
From | Date | Subject | |
---|---|---|---|
Next Message | Rstat | 2009-07-07 15:48:10 | Trying to find a low-cost program for Data migration and ETL |
Previous Message | David Fetter | 2009-07-07 15:40:06 | Re: combine multiple row values in to one row |