Re: Need "InBetween" (not just Before and After) Trigger - Mailing list pgsql-general

From Tom Lane
Subject Re: Need "InBetween" (not just Before and After) Trigger
Date
Msg-id 14399.979445852@sss.pgh.pa.us
Whole thread Raw
In response to Need "InBetween" (not just Before and After) Trigger  (Matt Doucleff <matt@digitalfountain.com>)
List pgsql-general
Matt Doucleff <matt@digitalfountain.com> writes:
> I want a trigger to happen after constraint checking but before row
> insertion.

In other words, you'd like your trigger to be able to violate the
constraints?

This does *not* strike me as a good idea.

> If I use a "before" trigger, the constraints are checked after I've
> already performed my action.  Thus I have performed my action yet no
> row is inserted (which is inconsistent).

> If I use an "after" trigger, the constraints are checked first.  If
> the row is inserted, I attempt to perform my action.  If my action
> fails, then I have an inserted row but no action, which is also
> inconsistent.

Seems to me this is all irrelevant, because in either case, the first
action will be rolled back if the second one fails.  There might be
some marginal amount of time wasted, which you could minimize by
arranging things so that the more-likely-to-fail action is done first.
But I see no correctness issue.

            regards, tom lane

pgsql-general by date:

Previous
From: Alvar Freude
Date:
Subject: Re: Compare dates.
Next
From: "Thomas T. Thai"
Date:
Subject: performance hit with --enable-debug