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

From Richard Huxton
Subject Re: How do I concatenate row-wise instead of column-wise?
Date
Msg-id 200207161015.53342.dev@archonet.com
Whole thread Raw
In response to How do I concatenate row-wise instead of column-wise?  (Marcus Claesson <marcus.claesson@angiogenetics.se>)
List 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 by date:

Previous
From: "Luis Alberto Amigo Navarro"
Date:
Subject: Re: [HACKERS] please help on query
Next
From: "Rajesh Kumar Mallah."
Date:
Subject: Cascading deletions does not seem to work inside PL/PGSQL functions.