Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by postgresql.org (Postfix) with ESMTP id 0E4FD475876 for ; Tue, 16 Jul 2002 05:30:02 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) id 17UOeg-0004yA-0U; Tue, 16 Jul 2002 10:30:02 +0100 Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id 833AB11E92; Tue, 16 Jul 2002 10:15:56 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: Marcus Claesson , 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 User-Agent: KMail/1.4.1 References: <3D33D4AA.1020600@angiogenetics.se> In-Reply-To: <3D33D4AA.1020600@angiogenetics.se> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200207161015.53342.dev@archonet.com> X-Archive-Number: 200207/235 X-Sequence-Number: 8613 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() whi= ch=20 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 defau= lt=20 you could have "ddd;eee;fff" or "fff;ddd;eee" etc. Go to techdocs.postgresql.org and check the "Postgresql Cookbook" courtesy = of=20 Roberto Mello and also the "Postgresql Notes" by me. Also check the online= =20 manual and the mailing archives (try searching on "aggregate" and "catenate= "=20 or "concat"). HTH - Richard Huxton