Re: interesting SQL puzzle - concatenating column with itself. - Mailing list pgsql-sql

From Nick Fankhauser
Subject Re: interesting SQL puzzle - concatenating column with itself.
Date
Msg-id 427E892A.1000107@ontko.com
Whole thread Raw
In response to Re: interesting SQL puzzle - concatenating column with itself.  (Alvaro Herrera <alvherre@dcc.uchile.cl>)
List 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@ontko.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.
> 



pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: interesting SQL puzzle - concatenating column with itself.
Next
From: "ALÝ ÇELÝK"
Date:
Subject: Re: diff value retuns, debug mode and play mode