multi column foreign key for implicitly unique columns - Mailing list pgsql-sql

From Markus Bertheau
Subject multi column foreign key for implicitly unique columns
Date
Msg-id 1092734724.2627.4.camel@dicaprio.akademie1.de
Whole thread Raw
Responses Re: multi column foreign key for implicitly unique columns
Re: multi column foreign key for implicitly unique columns
List pgsql-sql
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>



pgsql-sql by date:

Previous
From: Theo Galanakis
Date:
Subject: Re: CROSS-TAB query help? I have read it cant be done in on
Next
From: Oliver Elphick
Date:
Subject: Re: multi column foreign key for implicitly unique columns