Re: looking for alternative to MySQL's GROUP_CONCAT function - Mailing list pgsql-general

From David Fetter
Subject Re: looking for alternative to MySQL's GROUP_CONCAT function
Date
Msg-id 20051021202509.GA23082@fetter.org
Whole thread Raw
In response to looking for alternative to MySQL's GROUP_CONCAT function  (<x3v0-pgsql@yahoo.com>)
List pgsql-general
On Fri, Oct 21, 2005 at 11:58:07AM -0700, x3v0-pgsql@yahoo.com wrote:
> Hi all,
>
> I'm looking into PostgreSQL. Coming from a MySQL background, I have
> made heavy use of its very useful GROUP_CONCAT function. You can
> read about the function here:
>
> http://dev.mysql.com/doc/refman/4.1/en/group-by-functions.html
>
> Is there a PostgreSQL alternative to GROUP_CONCAT?

There's a more flexible one :)

Use the array_accum() aggregate as described here

http://www.postgresql.org/docs/current/static/xaggr.html

and wrap it with array_to_string()

http://www.postgresql.org/docs/current/static/functions-array.html

to get a nice, flexible system.  You can make a static one if you
like.  One thing about this approach is that you then have to exclude
NULLs from your search because PostgreSQL arrays can't yet hold NULLs.

Cheers,
D
--
David Fetter david@fetter.org http://fetter.org/
phone: +1 510 893 6100   mobile: +1 415 235 3778

Remember to vote!

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: looking for alternative to MySQL's GROUP_CONCAT function
Next
From: Tom Lane
Date:
Subject: Re: Handling of pad characters (was RE: Oracle buys Innobase )