Re: looking for alternative to MySQL's GROUP_CONCAT function

From: David Fetter <david(at)fetter(dot)org>
To: x3v0-pgsql(at)yahoo(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: looking for alternative to MySQL's GROUP_CONCAT function
Date: 2005-10-21 20:25:09
Message-ID: 20051021202509.GA23082@fetter.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Oct 21, 2005 at 11:58:07AM -0700, x3v0-pgsql(at)yahoo(dot)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(at)fetter(dot)org http://fetter.org/
phone: +1 510 893 6100 mobile: +1 415 235 3778

Remember to vote!

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-10-21 20:29:06 Re: Handling of pad characters (was RE: Oracle buys Innobase )
Previous Message Tom Lane 2005-10-21 20:12:19 Re: looking for alternative to MySQL's GROUP_CONCAT function