pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomasz Myrta <jasiek@klaster.net>
To: Objectz <objectz@postmark.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: String aggregate function
Date: Mon, 17 Mar 2003 11:55:58 +0100
Message-ID: <3E75A9BE.6080701@klaster.net> (raw)
In-Reply-To: <000c01c2ec70$f2e6f5f0$aea067d4@eg1opwxp107>
References: <000c01c2ec70$f2e6f5f0$aea067d4@eg1opwxp107>

Uz.ytkownik Objectz napisa?:
> Tomsaz,
> 
> Thnx a lot for the great reference It has what I need.
> 
> create function comma_aggregate(text,text) returns text as '
> begin
>   if (length($1) > 0 ) then
>     return $1 || ', ' || $2;
>   else
>     return $2;
>   end if;
> end;
> ' language 'plpgsql';
> 
> -- create the aggregate function
> 
> create aggregate comma (basetype=text, sfunc=comma_aggregate,
> stype=text, initcond='' );
> 
> 
> I need some help to expand on its funcitonality instead of calling
> comma(col_name) to produce comma-seperated values I need to call
> something like concattext(prefix, col_name, suffix) wich returns the
> list in one column with the prefix and suffix aroung each entry as
> specified.
> 
> This will enable me to produce something like this result
> 
> 
>>1		(text1) (text3)
>>2		(text2) (text5)
>>3		(text4) 
> 
> 
> With this query 
> Select type, concattext('(', text, ') ') from table group by type
> 
> Any help on how to convert the above comma function to receive the
> prefix and suffix parameters
> 
> Regards

Change this function to separate fields only with space character 
(instead of comma) and use as below:

select comma('(' || text ')') ...

Regards,
Tomasz Myrta




view thread (6+ messages)  latest in thread

Message-ID: <3E75A9BE.6080701@klaster.net>
Permalink:  ../3E75A9BE.6080701@klaster.net/
Also on:    postgresql.org/message-id/3E75A9BE.6080701@klaster.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: jasiek@klaster.net, objectz@postmark.net
  Subject: Re: String aggregate function
  In-Reply-To: <3E75A9BE.6080701@klaster.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