CREATE FUNCTION join_two_with_comma(text, text) RETURNS text
LANGUAGE sql
AS $_$
SELECT CASE
WHEN $2 IS NULL OR $2 = '' THEN $1
WHEN $1 IS NULL OR $1 = '' THEN $2
ELSE $1 || ', ' || $2
END
$_$;
CREATE AGGREGATE join_with_comma(text) (
SFUNC = join_two_with_comma,
STYPE = text,
INITCOND = ''
);
LANGUAGE sql
AS $_$
SELECT CASE
WHEN $2 IS NULL OR $2 = '' THEN $1
WHEN $1 IS NULL OR $1 = '' THEN $2
ELSE $1 || ', ' || $2
END
$_$;
CREATE AGGREGATE join_with_comma(text) (
SFUNC = join_two_with_comma,
STYPE = text,
INITCOND = ''
);