multi column foreign key for implicitly unique columns

Поиск
Список
Период
Сортировка
От Markus Bertheau
Тема multi column foreign key for implicitly unique columns
Дата
Msg-id 1092734724.2627.4.camel@dicaprio.akademie1.de
обсуждение исходный текст
Ответы Re: multi column foreign key for implicitly unique columns  (Oliver Elphick <olly@lfix.co.uk>)
Re: multi column foreign key for implicitly unique columns  (Richard Huxton <dev@archonet.com>)
Список 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 по дате отправления:

Предыдущее
От: Theo Galanakis
Дата:
Сообщение: Re: CROSS-TAB query help? I have read it cant be done in on
Следующее
От: Oliver Elphick
Дата:
Сообщение: Re: multi column foreign key for implicitly unique columns