| From: | "Mike G(dot)" <mike(at)thegodshalls(dot)com> | 
|---|---|
| To: | A Gilmore <agilmore(at)shaw(dot)ca> | 
| Cc: | PostgreSQL Novice <pgsql-novice(at)postgresql(dot)org> | 
| Subject: | Re: Concatenate rows | 
| Date: | 2005-02-21 03:34:27 | 
| Message-ID: | 20050221033427.GA8691@thegodshalls.thegodshalls | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | 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 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Fuhr | 2005-02-21 04:22:36 | Re: Concatenate rows | 
| Previous Message | A Gilmore | 2005-02-21 01:32:48 | Concatenate rows |