From: Markus Bertheau <twanger@bluetwanger.de>
To: pgsql-sql@postgresql.org
Subject: multi column foreign key for implicitly unique columns
Date: Tue, 17 Aug 2004 11:25:24 +0200
Message-ID: <1092734724.2627.4.camel@dicaprio.akademie1.de> (raw)
Hi,
PostgreSQL doesn't allow the creation of a foreign key to a combination
of fields that has got no dedicated unique key but is unique nonetheless
because a subset of the combination of fields has a unique constraint.
Example:
CREATE TABLE p (
name TEXT PRIMARY KEY,
"type" TEXT
);
CREATE TABLE f (
name TEXT,
"type" TEXT,
FOREIGN KEY(name, "type") REFERENCES p(name, "type")
);
ERROR: there is no unique constraint matching given keys for referenced table "p"
Is this on purpose? I think the foreign key should be allowed. Creating
an extra unique key only has a negative impact on performance, right?
Thanks
--
Markus Bertheau <twanger@bluetwanger.de>
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: twanger@bluetwanger.de
Subject: Re: multi column foreign key for implicitly unique columns
In-Reply-To: <1092734724.2627.4.camel@dicaprio.akademie1.de>
* 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