Re: combine multiple row values in to one row

Поиск
Список
Период
Сортировка
От David Fetter
Тема Re: combine multiple row values in to one row
Дата
Msg-id 20090707154304.GJ32215@fetter.org
обсуждение исходный текст
Ответ на Re: combine multiple row values in to one row  (David Fetter <david@fetter.org>)
Список 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@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate

В списке pgsql-general по дате отправления:

Предыдущее
От: Ransika de Silva
Дата:
Сообщение: Re: Table Partitioning : Having child tables in multiple database servers
Следующее
От: Dimitri Fontaine
Дата:
Сообщение: Re: Table Partitioning : Having child tables in multiple database servers