Re: Trigger question - Mailing list pgsql-general

From Nelio Alves Pereira Filho
Subject Re: Trigger question
Date
Msg-id 3A229514.2241079A@ifx.com.br
Whole thread Raw
In response to Trigger question  (Nelio Alves Pereira Filho <nelio@ifx.com.br>)
Responses Re: Trigger question
List pgsql-general
I got it.
But here's what I need to do: after any modification on the table, I
must run a procedure that will do some calculation, and then set these
values for each row. This calculation establishes relationships between
rows, and builds logically a tree. To accomplish all that, first I need
to unset some values, so I decided to use the BEFORE trigger to unset
these values, and the AFTER trigger to do this calculation.

Will I have to use explicit queries? And what's the real purpose of the
AFTER trigger?

Thanks


Tom Lane wrote:
>
> Nelio Alves Pereira Filho <nelio@ifx.com.br> writes:
> > create trigger set_counter after insert or update on nivel
> > for each row execute procedure set_counter();
>
> > The problem is that after I insert something, count value is still -1,
> > not 0!
>
> You want a BEFORE trigger, not an AFTER trigger.  AFTER is too late
> to affect the contents of the stored row.
>
>                         regards, tom lane

--
Nelio Alves Pereira Filho
IFX Networks
Sao Paulo / Brazil

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Trigger question
Next
From: Peter Eisentraut
Date:
Subject: Re: Bug? 'psql -l' in pg_ctl?