Re: Combining several rows - Mailing list pgsql-general

From Greg Stark
Subject Re: Combining several rows
Date
Msg-id 87k6z1q5q7.fsf@stark.xeocode.com
Whole thread Raw
In response to Combining several rows  (Matthias Nagl <pg@mnagl.de>)
List pgsql-general
Matthias Nagl <pg@mnagl.de> writes:

> For a table like this I am looking for a query that returns a result that
> looks this way:
>
>     name
> -------------
> abc, def, ghi

You need something like this:

create function concat_agg_accum(varchar, varchar) returns varchar
    as 'select $1 || '', '' || $2'
    language sql
    strict immutable;

create aggregate concat_agg (
    basetype = varchar,
    stype = varchar,
    sfunc = concat_agg_accum
);


select concat_agg(name) as name, ...

--
greg

pgsql-general by date:

Previous
From: Greg Stark
Date:
Subject: Re: how many record versions
Next
From: Philip
Date:
Subject: Re: pg_dump error