Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2013/8/6 Alvaro Herrera <alvherre@xxxxxxxxxxxxxxx>:
> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux