View Single Post

   
  #2 (permalink)  
Old 04-17-2008, 09:31 PM
Mike G.
 
Posts: n/a
Default Re: Concatenate rows

I suppose you could create a function, use a cursor to walk through the table row by row, assign the result of the each row fetched to the same variable each time.

CREATE FUNCTION returns text
DECLARE
a text;
single_row text;

BEGIN

FETCH CURSOR INTO

a := SELECT COLOR FROM X;

single_row := single_row || ':' || a;

LOOP;

END;

return single_row;


On Sun, Feb 20, 2005 at 05:32:48PM -0800, A Gilmore wrote:
> Hello,
>
> If I have a table like :
>
> ID COLOR
> 1 blue
> 2 red
> 3 green
>
> Could I write a SQL query that would return a single concatenated row
> for all matching rows, with a specified seperator. For example like so :
>
> blue:red:green:
>
> Thank you for your time,
> A Gilmore
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Reply With Quote