Re: Insertion Deferrable

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: 杨邕 <yayooo(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Insertion Deferrable
Date: 2004-10-29 18:33:16
Message-ID: 20041029111913.X28944@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 29 Oct 2004, [UTF-8] ^]^B^U wrote:

> You told me restricted foreign key cannot deferable in PostgreSQL 8.0.0 Beta 4.
>
> 2004-10-21 22:33 tgl
>
> * doc/src/sgml/ddl.sgml, doc/src/sgml/ref/create_table.sgml,
> src/backend/commands/tablecmds.c, src/backend/commands/trigger.c:
> Disallow referential integrity actions from being deferred; only
> the NO ACTION check is deferrable. This seems to be a closer
> approximation to what the SQL spec says than what we were doing
> before, and it prevents some anomalous behaviors that are
> possible now that triggers can fire during the execution of PL
> functions. Stephan Szabo.
>
> Take this test...
> Restricted foreign key allows insertion deferrable,
> And rejects deletion deferrable.

There's two separate concepts in foreign keys that are related.

There's the constraint check which makes sure that the constraint is
satisfied (ie, there is an appropriate matching row for each row from
the referencing table). This is deferrable.

There's also referential actions which occur when you change the
referenced table. These are not deferrable.

---

When you insert into a referencing table, at constraint check time (which
may be deferred), the check is applied.

When you delete from a referenced table, if there is a referential action
associated with the foreign key, it is done non-deferred. Technically,
the SQL model would also have a check a constraint check time, however in
your case the error from the referential action happens before that would
occur.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-10-29 19:20:10 Re: copy command PANIC in --encoding='utf8' createdb option
Previous Message Andreas Pflug 2004-10-29 18:07:57 Re: 22021: invalid byte sequence for encoding \"UNICODE\":