CREATE AGGREGATE group_concat(text) (
SFUNC=textcat,
STYPE=text
);
select group_concat(x) from unnest('{a,b,c,d}'::text[]) as x;
textcatis a function used inside an operator ||:
CREATE OPERATOR ||(
PROCEDURE = textcat,
LEFTARG = text,
RIGHTARG = text);
Update
Make a comma as a separator:
create or replace function group_concat_trans(text, text)
returns text
language sql
stable as
$$select concat($1,case when $1 is not null and $2 is not null then ',' end,$2)$$;
create aggregate group_concat(text) (
sfunc=group_concat_trans,
stype=text);
select group_concat(x) from unnest(array['a','b','c',null,'d']) as x;
╔═════════════╗
║ group_concat ║
╠══════════════╣
║ a,b,c,d ║
╚══════════════╝