Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jul 1, 3:09 pm, d...@xxxxxxxxxxxxx ("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



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux