| From: | Joe Conway <mail(at)joeconway(dot)com> |
|---|---|
| To: | Michael A Nachbaur <mike(at)nachbaur(dot)com> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: "Join" on delimeter aggregate query |
| Date: | 2003-06-08 01:03:50 |
| Message-ID: | 3EE28B76.9040501@joeconway.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Michael A Nachbaur wrote:
> Source Target
> joe(at)bob(dot)org address1(at)bob(dot)org,address2(at)bob(dot)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(at)bob(dot)org | address1(at)bob(dot)org
joe(at)bob(dot)org | address2(at)bob(dot)org
tom(at)bob(dot)org | address3(at)bob(dot)org
tom(at)bob(dot)org | address4(at)bob(dot)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(at)bob(dot)org | address1(at)bob(dot)org,address2(at)bob(dot)org
tom(at)bob(dot)org | address3(at)bob(dot)org,address4(at)bob(dot)org
(2 rows)
HTH,
Joe
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Josh Berkus | 2003-06-08 01:54:30 | Re: Elegant SQL solution: |
| Previous Message | Rod Taylor | 2003-06-07 23:57:17 | Re: (long) What's the problem? |