Re: How do I concatenate row-wise instead of column-wise?

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: How do I concatenate row-wise instead of column-wise?
Дата
Msg-id 200207161015.53342.dev@archonet.com
обсуждение исходный текст
Ответ на How do I concatenate row-wise instead of column-wise?  (Marcus Claesson <marcus.claesson@angiogenetics.se>)
Список pgsql-sql
On Tuesday 16 Jul 2002 9:09 am, Marcus Claesson wrote:
> I have a table like this:
> SELECT * FROM old_tab;
> id    |    descr
> -------------------
> 3    |    ddd
> 3    |    ddd
> 3    |    eee
> 3    |    fff

> SELECT * FROM new_tab;
> id    |    descr
> --------------------------
> 1    |    aaa;bbb
> 2    |    ccc;bbb
> 3    |    ddd;eee;fff
> 4    |    bbb

You'll want to write your own aggregate function - something like max() which
will work over a range of values. This is easier than you might think.

The only thing to be careful of is that order isn't guaranteed, so by default
you could have "ddd;eee;fff" or "fff;ddd;eee" etc.

Go to techdocs.postgresql.org and check the "Postgresql Cookbook" courtesy of
Roberto Mello and also the "Postgresql Notes" by me. Also check the online
manual and the mailing archives (try searching on "aggregate" and "catenate"
or "concat").

HTH

- Richard Huxton


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

Предыдущее
От: "Luis Alberto Amigo Navarro"
Дата:
Сообщение: Re: [HACKERS] please help on query
Следующее
От: "Rajesh Kumar Mallah."
Дата:
Сообщение: Cascading deletions does not seem to work inside PL/PGSQL functions.