On Jul 1, 3:09 pm, d(dot)(dot)(dot)(at)larkspark(dot)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