如何在Postgresql中产生自己的集合function

CREATE FUNCTION join_two_with_comma(texttextRETURNS 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 
= ''
);
原文地址:https://www.cnblogs.com/Hacker/p/1737868.html