我需要以不返回记录类型的方式重写此函数。原因是我需要使用它来创建视图。
CREATE OR REPLACE FUNCTION conta_relatos(IN _fator_normativo integer, IN _fator_determinativo integer, OUT rel_pri integer, OUT rel_sec integer, OUT rel_ref integer)
RETURNS record AS
$BODY$
DECLARE
tipo_relato text;
BEGIN
rel_pri := 0;
rel_sec := 0;
rel_ref := 0;
FOR tipo_relato IN
SELECT f."Tipo_Relato"
FROM "Vinculos" v
INNER JOIN ("Fontes" f INNER JOIN "Itens" i ON f."ID" = i."Fonte") ON v."Item" = i."ID"
WHERE v."Fator_Normativo" = _fator_normativo
AND v."Fator_Determinativo" = _fator_determinativo
LOOP
CASE tipo_relato
WHEN '1 - Relato Primário' THEN
rel_pri := rel_pri + 1;
WHEN '2 - Relato Secundário' THEN
rel_sec := rel_sec + 1;
WHEN '3 - Relato Referencial' THEN
rel_ref := rel_ref + 1;
END CASE;
END LOOP;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
该函数必须返回 3int
列:rel_pri
, rel_sec
,rel_ref