From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Terrence Brannon <metaperl@mac.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: how could a foreign key ever be NULL?
Date: Mon, 17 Dec 2001 12:15:20 -0800 (PST)
Message-ID: <20011217120557.X53003-100000@megazone23.bigpanda.com> (raw)
In-Reply-To: <8BBB36A0-F2E2-11D5-92F7-003065C2A10C@mac.com>
On Mon, 17 Dec 2001, Terrence Brannon wrote:
> The Momjian book states:
>
> A single-column foreign key is either NULL or matches a primary key
>
> But the problem I have with this statement is that a primary key
> cannot be null or duplicate. And since the foreign key references
> a value that is neither null or duplicate, how could it ever be
> NULL?
First, you don't need to reference a primary key. Any unique constraint
should work (11.8 referential constraint definition, Syntax rules 2a),
"If the <referenced table and columns> specifies a <reference column
list>, then the set of column names of that <reference column list>
shall be equal to the set of column names in the unique columns of
a unique constraint of the referenced table." You're probably confusing
it with the behavior that if no column list is given it goes to
the primary key columns (11.8 SR2b I believe).
As for the NULL part, 4.10.2 Table Constraints, (ignoring the not
implemented match partial), "A referential constraint is satisfied
if one of the following conditions is true, depending on the <match
option> specified in the <referntial constraint definition>:
- If no <match type> was specified then, for each row R1 of the
referencing table, either at least one of the values of the
referencing columns in R1 shall be a null value, or the value of
each referencing column in R1 shall be equal to the value of the
corresponding referenced column in some row of the referenced
table.
- If MATCH FULL was specified then, for each row R1 of the refer-
encing table, either the value of every referencing column in R1
shall be a null value, or the value of every referencing column
in R1 shall not be null and there shall be some row R2 of the
referenced table such that the value of each referencing col-
umn in R1 is equal to the value of the corresponding referenced
column in R2."
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sszabo@megazone23.bigpanda.com, metaperl@mac.com
Subject: Re: how could a foreign key ever be NULL?
In-Reply-To: <20011217120557.X53003-100000@megazone23.bigpanda.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox