Re: Trigger question

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nelio Alves Pereira Filho <nelio(at)ifx(dot)com(dot)br>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Trigger question
Date: 2000-11-27 17:20:20
Message-ID: 11294.975345620@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Nelio Alves Pereira Filho <nelio(at)ifx(dot)com(dot)br> writes:
> 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.

Why don't you just do all the work in the BEFORE trigger?

> And what's the real purpose of the AFTER trigger?

The sequence of events is

compute contents of tuple to insert/update (per the query)

apply BEFORE triggers

check constraints

insert tuple

apply AFTER triggers

You *must* use a BEFORE trigger if you want to alter the tuple
that was computed by the query. The point of an AFTER trigger
is that it won't be run until constraints have been passed,
so you can avoid doing potentially expensive work until you know
the tuple is good. You might use an AFTER trigger to propagate
changes into other tables, for example. But you can't change
the tuple.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2000-11-27 17:24:05 Re: Bug? 'psql -l' in pg_ctl?
Previous Message Marko Kreen 2000-11-27 17:16:51 Re: Re: [GENERAL] Warning: Don't delete those /tmp/.PGSQL.* files