pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mathieu Arnold <mat@mat.cc>
To: pgsql-sql@postgresql.org
Subject: aggregate...
Date: Tue, 14 May 2002 18:13:09 +0200
Message-ID: <1729482965.1021399989@andromede.reaumur.absolight.net> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <1729482965.1021399989@andromede.reaumur.absolight.net>
Permalink:  ../1729482965.1021399989@andromede.reaumur.absolight.net/
Also on:    postgresql.org/message-id/1729482965.1021399989@andromede.reaumur.absolight.net

 · 

reply

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: mat@mat.cc
  Subject: Re: aggregate...
  In-Reply-To: <1729482965.1021399989@andromede.reaumur.absolight.net>

* 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