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