From: | Nick Fankhauser <nickf(at)ontko(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl> |
Cc: | nickf(at)doxpop(dot)com, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: interesting SQL puzzle - concatenating column with itself. |
Date: | 2005-05-08 21:48:26 |
Message-ID: | 427E892A.1000107@ontko.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Excellent! Thanks for providing both the idea and an example. I didn't get the idea right away, but the example made it clear. I'll try that on my table and report back on how it works out.
Regards,
-Nick
------------------------------------------------------------------
Nick Fankhauser
nickf(at)ontko(dot)com Phone 765.935.4283 Fax 765.962.9788
Ray Ontko & Co. - Software Consulting Services
http://www.ontko.com
Alvaro Herrera wrote:
>
> You can create a custom aggregate to do concatenation and group by
> memo_id.
>
> create or replace function text_cat(text, text) returns text called on null input
> language sql immutable as 'select case when $1 is null then $2 when $2
> is null then $1 else $1 || '' '' || $2 end';
>
> create aggregate textcat (basetype = text, sfunc = text_cat, stype = text);
>
> create table memos (memo_id int, sequence int, memo_text text);
> insert into memos values (666, 3, 'jumped over');
> insert into memos values (666, 1, 'The quick');
> insert into memos values (666, 4, 'the lazy brown dog');
> insert into memos values (666, 2, 'red fox');
>
> select memo_id, textcat(memo_text) from (select * from memos order by
> memo_id, sequence) as foo group by memo_id;
>
>
> The order is not really guaranteed, though if this is a one-shot thing,
> you may get away with turning off hashed aggregates.
>
From | Date | Subject | |
---|---|---|---|
Next Message | AL ELK | 2005-05-09 14:05:25 | Re: diff value retuns, debug mode and play mode |
Previous Message | Alvaro Herrera | 2005-05-08 21:29:05 | Re: interesting SQL puzzle - concatenating column with itself. |