Re: "Join" on delimeter aggregate query - Mailing list pgsql-sql

From Joe Conway
Subject Re: "Join" on delimeter aggregate query
Date
Msg-id 3EE28B76.9040501@joeconway.com
Whole thread Raw
In response to "Join" on delimeter aggregate query  (Michael A Nachbaur <mike@nachbaur.com>)
List pgsql-sql
Michael A Nachbaur wrote:
> Source             Target
> joe@bob.org   address1@bob.org,address2@bob.org,....
> 

It isn't clear from your description what you want (to me, anyway), but 
I'd guess something like this:

regression=# select * from src2tgt;   source    |      target
-------------+------------------ joe@bob.org | address1@bob.org joe@bob.org | address2@bob.org tom@bob.org |
address3@bob.orgtom@bob.org | address4@bob.org
 
(4 rows)

create or replace function mylist(text,text) returns text as '
declare  result text;
begin  if $1 = '''' then    result := $2;  else    result := $1 || '','' || $2;  end if;  return result;
end;
' language 'plpgsql';

create aggregate tgtlist
(  BASETYPE = text,  SFUNC = mylist,  STYPE = text,  INITCOND = ''
);

regression=# select source, tgtlist(target) from src2tgt group by source;   source    |              tgtlist
-------------+----------------------------------- joe@bob.org | address1@bob.org,address2@bob.org tom@bob.org |
address3@bob.org,address4@bob.org
(2 rows)

HTH,

Joe



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Changing owner of function -- best method?
Next
From: Damien Dougan
Date:
Subject: Creating Views with Column Names based on Distinct Row Data