primary key of the
class="parameter">reftable is used. The
- A value inserted into these columns is matched against the
+ A value inserted into the referencing column(s) is matched against the
values of the referenced table and referenced columns using the
given match type. There are three match types: MATCH
FULL>, MATCH PARTIAL>, and MATCH
clause specifies the action to perform when a referenced column
in the referenced table is being updated to a new value. If the
row is updated, but the referenced column is not actually
- changed, no action is done. There are the following possible
+ changed, no action is done. Referential actions apart from the
+ check of NO ACTION can not be deferred even if
+ the constraint is deferrable. There are the following possible
actions for each clause:
Produce an error indicating that the deletion or update
- would create a foreign key constraint violation. This is
- the default action.
+ would create a foreign key constraint violation.
+ If the constraint is deferred, this
+ error will be produced at constraint check time if there still
+ exist any referencing rows. This is the default action.
RESTRICT
- Same as NO ACTION except that this action
- will not be deferred even if the rest of the constraint is
- deferrable and deferred.
+ Produce an error indicating that the deletion or update
+ would create a foreign key constraint violation.
+ This is the same as NO ACTION except that
+ the check is not deferrable.
SET NULL
- Set the referencing column values to null.
+ Set the referencing column(s) to null.
SET DEFAULT
- Set the referencing column values to their default value.
+ Set the referencing column(s) to their default values.
- If primary key column is updated frequently, it may be wise to
- add an index to the foreign key column so that NO
- ACTION and CASCADE actions
- associated with the foreign key column can be more efficiently
- performed.
+ If the referenced column(s) are changed frequently, it may be wise to
+ add an index to the foreign key column so that referential actions
+ associated with the foreign key column can be performed more
+ efficiently.
CREATE TABLE cinemas (
- id serial,
- name text,
- location text
+ id serial,
+ name text,
+ location text
) TABLESPACE diskvol1;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.135 2004/10/16 21:16:36 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.136 2004/10/21 21:33:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
fk_trigger->actions[1] = '\0';
fk_trigger->isconstraint = true;
- fk_trigger->deferrable = fkconstraint->deferrable;
- fk_trigger->initdeferred = fkconstraint->initdeferred;
fk_trigger->constrrel = myRel;
switch (fkconstraint->fk_del_action)
{
case FKCONSTR_ACTION_NOACTION:
+ fk_trigger->deferrable = fkconstraint->deferrable;
+ fk_trigger->initdeferred = fkconstraint->initdeferred;
fk_trigger->funcname = SystemFuncName("RI_FKey_noaction_del");
break;
case FKCONSTR_ACTION_RESTRICT:
fk_trigger->funcname = SystemFuncName("RI_FKey_restrict_del");
break;
case FKCONSTR_ACTION_CASCADE:
+ fk_trigger->deferrable = false;
+ fk_trigger->initdeferred = false;
fk_trigger->funcname = SystemFuncName("RI_FKey_cascade_del");
break;
case FKCONSTR_ACTION_SETNULL:
+ fk_trigger->deferrable = false;
+ fk_trigger->initdeferred = false;
fk_trigger->funcname = SystemFuncName("RI_FKey_setnull_del");
break;
case FKCONSTR_ACTION_SETDEFAULT:
+ fk_trigger->deferrable = false;
+ fk_trigger->initdeferred = false;
fk_trigger->funcname = SystemFuncName("RI_FKey_setdefault_del");
break;
default:
fk_trigger->actions[0] = 'u';
fk_trigger->actions[1] = '\0';
fk_trigger->isconstraint = true;
- fk_trigger->deferrable = fkconstraint->deferrable;
- fk_trigger->initdeferred = fkconstraint->initdeferred;
fk_trigger->constrrel = myRel;
switch (fkconstraint->fk_upd_action)
{
case FKCONSTR_ACTION_NOACTION:
+ fk_trigger->deferrable = fkconstraint->deferrable;
+ fk_trigger->initdeferred = fkconstraint->initdeferred;
fk_trigger->funcname = SystemFuncName("RI_FKey_noaction_upd");
break;
case FKCONSTR_ACTION_RESTRICT:
fk_trigger->funcname = SystemFuncName("RI_FKey_restrict_upd");
break;
case FKCONSTR_ACTION_CASCADE:
+ fk_trigger->deferrable = false;
+ fk_trigger->initdeferred = false;
fk_trigger->funcname = SystemFuncName("RI_FKey_cascade_upd");
break;
case FKCONSTR_ACTION_SETNULL:
+ fk_trigger->deferrable = false;
+ fk_trigger->initdeferred = false;
fk_trigger->funcname = SystemFuncName("RI_FKey_setnull_upd");
break;
case FKCONSTR_ACTION_SETDEFAULT:
+ fk_trigger->deferrable = false;
+ fk_trigger->initdeferred = false;
fk_trigger->funcname = SystemFuncName("RI_FKey_setdefault_upd");
break;
default:
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.172 2004/09/10 18:39:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.173 2004/10/21 21:33:59 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* If we found some, check that they fit the deferrability
- * but skip ON RESTRICT ones, since they are
+ * but skip referential action ones, since they are
* silently never deferrable.
*/
if (pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_UPD &&
- pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_DEL)
+ pg_trigger->tgfoid != F_RI_FKEY_RESTRICT_DEL &&
+ pg_trigger->tgfoid != F_RI_FKEY_CASCADE_UPD &&
+ pg_trigger->tgfoid != F_RI_FKEY_CASCADE_DEL &&
+ pg_trigger->tgfoid != F_RI_FKEY_SETNULL_UPD &&
+ pg_trigger->tgfoid != F_RI_FKEY_SETNULL_DEL &&
+ pg_trigger->tgfoid != F_RI_FKEY_SETDEFAULT_UPD &&
+ pg_trigger->tgfoid != F_RI_FKEY_SETDEFAULT_DEL)
{
if (stmt->deferred && !pg_trigger->tgdeferrable)
ereport(ERROR,