aggregate...

From: Mathieu Arnold <mat(at)mat(dot)cc>
To: pgsql-sql(at)postgresql(dot)org
Subject: aggregate...
Date: 2002-05-14 16:13:09
Message-ID: 1729482965.1021399989@andromede.reaumur.absolight.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(at)mat(dot)cc, mat(at)absolight(dot)fr
isa | isa(at)mat(dot)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(at)mat(dot)cc,mat(at)absolight(dot)fr
isa | isa(at)mat(dot)cc

or :

select user, list(email, '|') from user join email using (id_user);

user | list
-------+-----------------------------
mat | mat(at)mat(dot)cc|mat(at)absolight(dot)fr
isa | isa(at)mat(dot)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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Scott Royston 2002-05-14 18:56:33 can't cast varchar as integer?
Previous Message Christoph Haller 2002-05-14 13:58:23 Re: order by <something wierd>