Re: Own messages for constraints? - Mailing list pgsql-general

From Jeff Davis
Subject Re: Own messages for constraints?
Date
Msg-id 1174329060.23455.373.camel@dogma.v10.wvs
Whole thread Raw
In response to Re: Own messages for constraints?  ("hubert depesz lubaczewski" <depesz@gmail.com>)
List pgsql-general
On Mon, 2007-03-19 at 19:08 +0100, hubert depesz lubaczewski wrote:
> On 3/19/07, Jeff Davis <pgsql@j-davis.com> wrote:
> > You can use an AFTER trigger instead of a CHECK constraint (but that may
> > have a performance impact - test for your application).
>
> are you sure you meant AFTER? why? generally data-checks should be in
> before triggers. i guess.
>

If you do the check BEFORE, you have to make sure that no other BEFORE
triggers that execute afterward modify the data again.

Assuming your AFTER trigger is on INSERT and UPDATE, there is no way for
a subsequent AFTER trigger to modify the data to be invalid. So an AFTER
trigger is more of an assurance that your data is valid.

Note that AFTER triggers need to queue up, so if you do a huge update
and have an AFTER trigger, it might use a lot of memory. BEFORE triggers
don't have that problem. If you're very concerned about this you could
use a BEFORE trigger and just make sure that no other trigger will cause
a problem.

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Possible planner bug?
Next
From: Howard Cole
Date:
Subject: TSearch2 Problems