Re: Concatenate rows

Поиск
Список
Период
Сортировка
От Mike G.
Тема Re: Concatenate rows
Дата
Msg-id 20050221033427.GA8691@thegodshalls.thegodshalls
обсуждение исходный текст
Ответ на Concatenate rows  (A Gilmore <agilmore@shaw.ca>)
Список 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 по дате отправления:

Предыдущее
От: A Gilmore
Дата:
Сообщение: Concatenate rows
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: Concatenate rows