-- string concatenation aggregate

create or replace function
	addonto(state text, next text) returns text
as $$
select state||','||next;
$$ language sql;

create or replace function
	stripcomma(str text) returns text
as $$
begin
	return substring(str,2);
end;
$$ language plpgsql;

create or replace aggregate cat2(text) (
	stype     = text,
	sfunc     = addonto,
	initcond  = '',
	finalfunc = stripcomma
);

