Re: Concatenate rows - Mailing list pgsql-novice

From Mike G.
Subject Re: Concatenate rows
Date
Msg-id 20050221033427.GA8691@thegodshalls.thegodshalls
Whole thread Raw
In response to Concatenate rows  (A Gilmore <agilmore@shaw.ca>)
List pgsql-novice
I suppose you could create a function, use a cursor to walk through the table row by row, assign the result of the each
rowfetched 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

pgsql-novice by date:

Previous
From: A Gilmore
Date:
Subject: Concatenate rows
Next
From: Michael Fuhr
Date:
Subject: Re: Concatenate rows