/* -*- sql -*- postgres specific registered procedures, require the plpgsql language installed*/DROPFUNCTIONIFEXISTScomma_join(anyarray)CASCADE;CREATEFUNCTIONcomma_join(anyarray)RETURNStextAS$$SELECTarray_to_string($1,', ')$$LANGUAGESQL;;DROPFUNCTIONIFEXISTScw_array_append_unique(anyarray,anyelement)CASCADE;CREATEFUNCTIONcw_array_append_unique(anyarray,anyelement)RETURNSanyarrayAS$$SELECTarray_append($1,(SELECT$2WHERE$2<>ALL($1)))$$LANGUAGESQL;;DROPAGGREGATEIFEXISTSgroup_concat(anyelement)CASCADE;CREATEAGGREGATEgroup_concat(basetype=anyelement,sfunc=cw_array_append_unique,stype=anyarray,finalfunc=comma_join,initcond='{}');;DROPFUNCTIONIFEXISTSlimit_size(fulltexttext,formattext,maxsizeinteger);CREATEFUNCTIONlimit_size(fulltexttext,formattext,maxsizeinteger)RETURNStextAS$$DECLAREplaintexttext;BEGINIFchar_length(fulltext)<maxsizeTHENRETURNfulltext;ENDIF;IFformat='text/html'ORformat='text/xhtml'ORformat='text/xml'THENplaintext:=regexp_replace(fulltext,'<[a-zA-Z/][^>]*>','','g');ELSEplaintext:=fulltext;ENDIF;IFchar_length(plaintext)<maxsizeTHENRETURNplaintext;ELSERETURNsubstring(plaintextfrom1formaxsize)||'...';ENDIF;END$$LANGUAGEplpgsql;;DROPFUNCTIONIFEXISTStext_limit_size(fulltexttext,maxsizeinteger);CREATEFUNCTIONtext_limit_size(fulltexttext,maxsizeinteger)RETURNStextAS$$BEGINRETURNlimit_size(fulltext,'text/plain',maxsize);END$$LANGUAGEplpgsql;;