principlesqlCritical
MATCH FULL vs MATCH SIMPLE in foreign key constraints
Viewed 0 times
simplefullconstraintsmatchforeignkey
Problem
I've noticed the clauses
The default is
MATCH SIMPLE and MATCH FULL in phpPgAdmin, but I can't find a description in the docs.The default is
MATCH SIMPLE. How do they function?Solution
Check the
There are three match types:
(which is the default).
a multicolumn foreign key to be null unless all foreign key columns
are null; if they are all null, the row is not required to have a
match in the referenced table.
key columns to be null; if any of them are null, the row is not
required to have a match in the referenced table.
yet implemented. (Of course,
the referencing column(s) to prevent these cases from arising.)
Also, in the chapter on Foreign Keys:
Normally, a referencing row need not satisfy the foreign key
constraint if any of its referencing columns are null. If
is added to the foreign key declaration, a referencing row escapes
satisfying the constraint only if all its referencing columns are null
(so a mix of null and non-null values is guaranteed to fail a
constraint). If you don't want referencing rows to be able to
avoid satisfying the foreign key constraint, declare the referencing
column(s) as
And be sure to consult the current manual or the version matching your installation. Don't fall for outdated Google links to outdated versions.
CREATE TABLE page of the manual:There are three match types:
MATCH FULL, MATCH PARTIAL, and MATCH SIMPLE(which is the default).
MATCH FULL will not allow one column ofa multicolumn foreign key to be null unless all foreign key columns
are null; if they are all null, the row is not required to have a
match in the referenced table.
MATCH SIMPLE allows any of the foreignkey columns to be null; if any of them are null, the row is not
required to have a match in the referenced table.
MATCH PARTIAL is notyet implemented. (Of course,
NOT NULL constraints can be applied tothe referencing column(s) to prevent these cases from arising.)
Also, in the chapter on Foreign Keys:
Normally, a referencing row need not satisfy the foreign key
constraint if any of its referencing columns are null. If
MATCH FULLis added to the foreign key declaration, a referencing row escapes
satisfying the constraint only if all its referencing columns are null
(so a mix of null and non-null values is guaranteed to fail a
MATCH FULLconstraint). If you don't want referencing rows to be able to
avoid satisfying the foreign key constraint, declare the referencing
column(s) as
NOT NULL.And be sure to consult the current manual or the version matching your installation. Don't fall for outdated Google links to outdated versions.
Context
StackExchange Database Administrators Q#58894, answer score: 68
Revisions (0)
No revisions yet.