create schema t;
set current_schema to 't';
create table t(id text, v text);
insert into t(id, v) values('1','a'),('2','b'),('1','c'),('2','d');
select group_concat(id,v separator ';') into tmp_table from t;
select * from tmp_table;
group_concat
--------------
1a;2b;1c;2d
(1 row)
set explain_perf_mode=pretty;
explain verbose select id, group_concat(VARIADIC ARRAY[id,':',v] order by id) as title from t group by id;
QUERY PLAN
----------------------------------------------------------------------------------------------------
GroupAggregate (cost=61.11..70.13 rows=200 width=8256)
Output: id, group_concat(VARIADIC ARRAY[id, ':'::text, v] ORDER BY id NULLS FIRST SEPARATOR ',')
Group By Key: t.id
-> Sort (cost=61.11..63.28 rows=869 width=64)
Output: id, v
Sort Key: t.id COLLATE utf8mb4_general_ci
-> Seq Scan on t.t (cost=0.00..18.69 rows=869 width=64)
Output: id, v
(8 rows)
drop schema t cascade;
NOTICE: drop cascades to 2 other objects
DETAIL: drop cascades to table t
drop cascades to table tmp_table
reset current_schema;