From: Tom Lane <tgl@sss.pgh.pa.us>
To: Stephan Szabo <sszabo@megazone.bigpanda.com>
Cc: Richard Huxton <dev@archonet.com>
Cc: Markus Bertheau <twanger@bluetwanger.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: multi column foreign key for implicitly unique columns
Date: Tue, 17 Aug 2004 10:46:35 -0400
Message-ID: <4307.1092753995@sss.pgh.pa.us> (raw)
In-Reply-To: <20040817072443.S60684@megazone.bigpanda.com>
References: <1092734724.2627.4.camel@dicaprio.akademie1.de>
<4121D55D.1040105@archonet.com>
<20040817072443.S60684@megazone.bigpanda.com>
Stephan Szabo <sszabo@megazone.bigpanda.com> writes:
> No, actually, it's that the SQL92 (at least) spec says explicitly that
> there must be a unique constraint across all of the columns specified, not
> merely across a subset.
> "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."
SQL99 says the same. 11.8 syntax rule 3a:
a) If the <referenced table and columns> specifies a <reference
column list>, then the set of <column name>s contained
in that <reference column list> shall be equal to the
set of <column name>s contained in the <unique column
list> of a unique constraint of the referenced table.
I think one reason for this is that otherwise it's not clear which
unique constraint the FK constraint depends on. Consider
create table a (f1 int unique, f2 int unique);
create table b (f1 int, f2 int,
foreign key (f1,f2) references a(f1,f2));
How would you decide which constraint to make the FK depend on?
It'd be purely arbitrary.
regards, tom lane
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: tgl@sss.pgh.pa.us, sszabo@megazone.bigpanda.com, dev@archonet.com, twanger@bluetwanger.de
Subject: Re: multi column foreign key for implicitly unique columns
In-Reply-To: <4307.1092753995@sss.pgh.pa.us>
* 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