Postgres Function End Loop e erro de retorno

Eu tentei criar essa função, mas o sistema está retornando um "erro LOOP" e não sei como retornar 3 variáveis ​​ao mesmo tempo. Eu tentei arduamente descobrir isso, mas não encontrei uma resposta em nenhum lugar.

CREATE OR REPLACE FUNCTION conta_relatos(fator_normativo integer, fator_determinativo integer)
  RETURNS integer AS
$BODY$
DECLARE
    vinculos_encontrados RECORD;
    rel_pri INT;
rel_sec INT;
rel_ref INT;
no_item INT;
tipo_relato TEXT;
BEGIN
    rel_pri := 0;
    rel_sec := 0;
    rel_ref := 0;    
FOR vinculos_encontrados IN SELECT * FROM "Vinculos" WHERE ("Vinculos"."Fator_Normativo" =   Fator_Normativo AND "Vinculos"."Fator_Determinativo" = Fator_Determinativo) LOOP
    no_item := vinculos_encontrados."Item";
SELECT "Fontes"."Tipo_Relato" INTO tipo_relato FROM "Fontes" WHERE "Fontes"."ID" = no_item;
--IF tipo_relato = "1 - Relato Primário" THEN 
   rel_pri := rel_pri + 1;
--ELSE IF tipo_relato = "2 - Relato Secundário" THEN 
   rel_sec := rel_sec + 1;
--ELSE IF tipo_relato = "3 - Relato Referencial" THEN 
   rel_ref := rel_ref + 1;
    --END IF;
    END LOOP;
    RETURN rel_pri, rel_sec, rel_ref;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

questionAnswers(2)

yourAnswerToTheQuestion