Claudio Rogerio Carvalho Filho escreveu:
> Estou com problema nessa consulta. Já sei que o erro é na linha em
> negrito, a rotina esta MUITO LENTA. Observem que eu não sei como fazer
> um sql dentro de uma função, dai me utilizei de um FOR.
>
>
>
> ALGUEM PODERIA ME AJUDAR A FAZER ESTA ROTINA FICAR MAIS RAPIDA?
>
>
>
> CREATE OR REPLACE FUNCTION func_tem_atos_digitados(xmesref bpchar,
> xcontrole integer)
> RETURNS boolean AS
> $BODY$
> declare
> tbARQEXA RECORD;
> begin
> FOR tbARQEXA IN select * from arqexa where mesref = xmesref and
> controle = xcontrole limit 1 LOOP END LOOP;
>
> if (not found) then
> return false;
> else
> return true;
> end if;
> end;
> $BODY$
> LANGUAGE 'plpgsql' VOLATILE;
> ALTER FUNCTION func_tem_atos_digitados(xmesref bpchar, xcontrole
> integer) OWNER TO postgres;
>
Faça-a mais simples:
CREATE OR REPLACE FUNCTION func_tem_atos_digitados(xmesref bpchar,
xcontrole integer)
RETURNS boolean AS
$$
SELECT EXISTS(SELECT 1 FROM arqexa
WHERE mesref = $1 AND controle = $2);
$$
LANGUAGE SQL;
Osvaldo
PS. Se arqexa for um tabela com muitos registros existem índices nos
campos mesref e controle? Estatísticas atualizadas?
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral