Re: How do I aggregate data from multiple rows into a delimited list?

Поиск
Список
Период
Сортировка
От Gunzler
Тема Re: How do I aggregate data from multiple rows into a delimited list?
Дата
Msg-id 1183506655.311805.253130@i38g2000prf.googlegroups.com
обсуждение исходный текст
Ответ на How do I aggregate data from multiple rows into a delimited list?  ("D. Dante Lorenso" <dante@larkspark.com>)
Список pgsql-general
On Jul 1, 3:09 pm, d...@larkspark.com ("D. Dante Lorenso") wrote:
> I want to select several rows of data and have them returned in a single
> record with the rows joined by a delimiter.  It would be great if this
> could be done in a generic way possibly using the GROUP BY like this:

I recently wrote this to address the same need. I practically copied
it straight from the "CREATE AGGREGATE" documentation, so look there
for more information. It will create a "text_accumulate" aggregate
function that does what you need:

CREATE FUNCTION text_append(text,text) RETURNS text
  AS 'select $1 || '','' || $2;'
  LANGUAGE SQL
  IMMUTABLE
  RETURNS NULL ON NULL INPUT;

CREATE AGGREGATE text_accumulate(
  BASETYPE = text,
  SFUNC = text_append,
  STYPE = text
);


Geoff


В списке pgsql-general по дате отправления:

Предыдущее
От: Andrew Sullivan
Дата:
Сообщение: Re: dropdb ; createdb equivalent without createdb permission?
Следующее
От: "E.J. Moloney"
Дата:
Сообщение: Vacuum issue