Em 16/12/10, [email protected]<[email protected]> escreveu:
> CREATE OR REPLACE FUNCTION "public"."f_rep_tarefa_concluida" (
> )
> RETURNS trigger AS
> $body$
> DECLARE
>      rec           RECORD;
>      dataini      TIMESTAMP(0);
>      datafim     TIMESTAMP(0);
>      flag           BOOLEAN;
> BEGIN
>      IF OLD.estado = '0' and NEW.estado = '1' THEN
>          perform zera_calc_rep(NEW.idrepesportesmt);
>
>          FOR rec IN select idrel_tarefasrep, idprog from rel_tarefasrep
> where idrepesportesmt = NEW.idrepesportesmt LOOP
>              dataini = now();
>              flag = f_rodar_reportagem(NEW.idrepesportesmt, rec.idprog);
>              datafim = now();
>
>              IF flag = true THEN
>                update rel_tarefasrep set
>                       rodado = true
>                where idrel_tarefasrep = rec.idrel_tarefasrep;
>
> --               insert into hist_relatorio_reportagem values (0,
> rec.idrel_tarefasrep, dataini, datafim, '', '0');
>              END IF;
>          END LOOP;
>      END IF;
>
>      RETURN NULL;
> END;
> $body$
> LANGUAGE 'plpgsql'
> VOLATILE
> CALLED ON NULL INPUT
> SECURITY INVOKER
> COST 100;
>


Apenas uma observação:
Você efetivamente deseja que o conteúdo de dataini e datafim seja o
momento do início da transação?

Fica difícil comentar alguma coisa sem saber se "zera_calc_rep" e
"f_rodar_reportagem" envolvem um processamento demorado ou não, se
"select idrel_tarefasrep, idprog from rel_tarefasrep where
idrepesportesmt = NEW.idrepesportesmt" retorna um volume astronômico
de registros ou não.

É uma trigger AFTER?

O auto-vacuum está devidamente configurado?

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

Responder a