Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 839494768E3 for ; Tue, 14 May 2002 13:08:17 -0400 (EDT) Received: from aragorn.reaumur.absolight.net (ATuileries-113-2-1-180.abo.wanadoo.fr [80.11.216.180]) by postgresql.org (Postfix) with ESMTP id 655FF476C40 for ; Tue, 14 May 2002 12:11:14 -0400 (EDT) Received: from andromede.reaumur.absolight.net (andromede.reaumur.absolight.net [212.43.217.61]) by aragorn.reaumur.absolight.net (Postfix) with ESMTP id 5F482D70E for ; Tue, 14 May 2002 18:11:19 +0200 (CEST) Date: Tue, 14 May 2002 18:13:09 +0200 From: Mathieu Arnold To: pgsql-sql@postgresql.org Subject: aggregate... Message-ID: <1729482965.1021399989@andromede.reaumur.absolight.net> X-Mailer: Mulberry/2.2.1 (Win32) X-wazaaa: True, true MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Archive-Number: 200205/139 X-Sequence-Number: 7775 Hi I have this : CREATE FUNCTION "comma_cat" (text,text) RETURNS text AS ' SELECT CASE WHEN $2 IS NULL OR $2 = '''' THEN $1 WHEN $1 IS NULL OR $1 = '''' THEN $2 ELSE $1 || '', '' || $2 END ' LANGUAGE 'sql'; CREATE AGGREGATE list ( BASETYPE = text, SFUNC = comma_cat, STYPE = text, INITCOND = '' ); I can use it as : select user, list(email) from user join email using (id_user); user | list -------+----------------------------- mat | mat@mat.cc, mat@absolight.fr isa | isa@mat.cc but now, I'd like a better version of this function/aggregate couple which would allow me to do something like : select user, list(email, ',') from user join email using (id_user); user | list -------+----------------------------- mat | mat@mat.cc,mat@absolight.fr isa | isa@mat.cc or : select user, list(email, '|') from user join email using (id_user); user | list -------+----------------------------- mat | mat@mat.cc|mat@absolight.fr isa | isa@mat.cc I know I'd have to modify the function to take a third argument (easy) but I don't know how to use a 2 argument aggregate (I don't even know if it's possible). -- Mathieu Arnold