Re: TRIGGER BEFORE INSERT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com>
Cc: Jerry Sievers <jerry(at)jerrysievers(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: TRIGGER BEFORE INSERT
Date: 2007-01-09 15:44:16
Message-ID: 7821.1168357456@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com> writes:
> 1. either the new value of "test_days.dnia" as already present in the
> NEW row, is not visible to "UPDATE test_utarg" sub-statement of the same
> transaction. But earlier versions of Postgres did allow for that
> visibility.
> 2. or the constrainets in earlier postgres were checked on trigger
> transaction COMMIT, not along the way; so the constraint violation
> didn't occure then.

Current versions of PG check foreign keys at the end of each
insert/update/delete statement, so your before-insert trigger is in fact
erroneous: the referenced key does not yet exist in the target table.
I think 7.2 did constraint checking only when the entire interactive
command finished, but there were enough cases where that was wrong
that we changed it.

Consider declaring the foreign-key constraint as DEFERRED.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2007-01-09 16:06:33 Operator performance question
Previous Message Tom Lane 2007-01-09 15:33:52 Re: Questions about horizontal partitioning