From: Richard Huxton <dev@archonet.com>
To: Marcus Claesson <marcus.claesson@angiogenetics.se>
To: pgsql-sql@postgresql.org
Subject: Re: How do I concatenate row-wise instead of column-wise?
Date: Tue, 16 Jul 2002 10:15:51 +0100
Message-ID: <200207161015.53342.dev@archonet.com> (raw)
In-Reply-To: <3D33D4AA.1020600@angiogenetics.se>
References: <3D33D4AA.1020600@angiogenetics.se>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: dev@archonet.com, marcus.claesson@angiogenetics.se
Subject: Re: How do I concatenate row-wise instead of column-wise?
In-Reply-To: <200207161015.53342.dev@archonet.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox