Boa noite Pessoal,
vejam se podem me ajudar, tenho um a função no postgresql 9.4 que me
retorna um json, mas esta ocorrendo erro ao executar a mesma, sendo que se
executar somente o select do json, está funcionando, logo acho que é algo
em relação ao retorno da função..

retornando o erro:
ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function get_historico_mensagem(integer,character
varying) line 11 at SQL statement



CREATE OR REPLACE FUNCTION public.get_historico_mail(
    _idmail integer,
    _token character varying)
  RETURNS json AS

  --DECLARE
  _tokencal varchar;

  BEGIN
  _tokencal=CAST(_idmail as VARCHAR);
IF EXISTS (SELECT 1 from maillog where idmail=_idmail) then
IF getmd5(_token,_tokencal) THEN
SELECT row_to_json(r)
FROM
(SELECT array_agg(mp.idmail) idmail, array_agg(mp.telefone) telefone,
array_agg(mp.datahoraenvio) datahoraenvio, array_agg(mp.id) id,
 array_agg(mp.dtregistro) dtregistro, array_agg(mp.datahoraenvio)  dtenvio
      FROM maillog mp where mp.idmail=_idmail
      ) r
   where r IS NOT NULL;
else
RAISE EXCEPTION '%','INVALID TOKEN';
END IF;
else
RAISE EXCEPTION '%','mail não encontrado ('||_idmail||')';
END IF;
  END;
$BODY$
  LANGUAGE plpgsql VOLATILE SECURITY DEFINER


-- 

Douglas Fabiano Specht
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a