Re: Seamless replacement to MySQL's GROUP_CONCAT function...

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: "immersive(dot)excel(at)gmail(dot)com" <immersive(dot)excel(at)gmail(dot)com>, x3v0-pgsql(at)yahoo(dot)com, pgsql-general(at)postgresql(dot)org, David Fetter <david(at)fetter(dot)org>
Subject: Re: Seamless replacement to MySQL's GROUP_CONCAT function...
Date: 2013-08-06 05:47:47
Message-ID: CAFj8pRD0-J-_c_bL7AAazuo+W4QhcRfJjOFkOpKpPnXRUjNUXw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2013/8/6 Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>:
> Pavel Stehule escribió:
>
>> you code can be translated to
>>
>> CREATE OR REPLACE
>> FUNCTION GROUP_CONCAT_ATOM(field1 TEXT, field2 TEXT, delimiter TEXT)
>> RETURNS TEXT AS $$
>> BEGIN
>> RETURN COALESCE(field1||delimiter||field2, field2, field1);
>> END;
>> $$ LANGUAGE plpgsql;
>
> Actually you don't even need plpgsql for this, do you ..

There is better optimized plpgsql - not sure, why - probably, so there
is not possible inlining .. and start of SQL engine is little bit
slower than start of plpgsql.

postgres=# create table f(a text, b int);
CREATE TABLE
postgres=# insert into f select 'Ahoj', random()*100 from
generate_series(1,10000);

select group_concat(a,',') from f group by b;

PL/pgSQL .. 36 ms
SQL .. 49 ms

Regards

Pavel Stehule

>
> --
> Álvaro Herrera http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message liuyuanyuan 2013-08-06 07:12:53 inserting huge file into bytea cause out of memory
Previous Message immersive.excel@gmail.com 2013-08-06 05:41:06 Re: Seamless replacement to MySQL's GROUP_CONCAT function...