如何在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 
= ''
);

 

 

 

posted @ 2010-05-18 08:05  James  阅读(179)  评论(0编辑  收藏  举报