Re: Seamless replacement to MySQL's GROUP_CONCAT function... - Mailing list pgsql-general

From Pavel Stehule
Subject Re: Seamless replacement to MySQL's GROUP_CONCAT function...
Date
Msg-id CAFj8pRD0-J-_c_bL7AAazuo+W4QhcRfJjOFkOpKpPnXRUjNUXw@mail.gmail.com
Whole thread Raw
In response to Re: Seamless replacement to MySQL's GROUP_CONCAT function...  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Responses Re: Seamless replacement to MySQL's GROUP_CONCAT function...  ("immersive.excel@gmail.com" <immersive.excel@gmail.com>)
List pgsql-general
2013/8/6 Alvaro Herrera <alvherre@2ndquadrant.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


pgsql-general by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Seamless replacement to MySQL's GROUP_CONCAT function...
Next
From: liuyuanyuan
Date:
Subject: inserting huge file into bytea cause out of memory