Table inheritance foreign key problem

Поиск
Список
Период
Сортировка
От Andy Chambers
Тема Table inheritance foreign key problem
Дата
Msg-id op.vn3ocuc3cqhz04@vaio.hsd1.md.comcast.net
обсуждение исходный текст
Ответы Re: Table inheritance foreign key problem  (Richard Broersma <richard.broersma@gmail.com>)
Re: Table inheritance foreign key problem  (David Fetter <david@fetter.org>)
Список pgsql-general
Hi,

One of the caveats described in the documentation for table inheritance is
that foreign key constraints cannot cover the case where you want to check
that a value is found somewhere in a table or in that table's
descendants.  It says there is no "good" workaround for this.

What about using check constraints?

So say you've got cities and capitals from the example and you had some
other table that wanted to put a foreign key on cities (plus capitals).
For example, lets keep "guidebook" info for the cities.  Some cities are
worthy of guidebooks even though they're not capitals.  Rather than put a
foreign key constraint on "city", would the following work?  What are the
drawbacks?

create table guidebooks (
   city check (city in (select name
                          from cities)),
   isbn text,
   author text,
   publisher text);

insert into guidebooks ('Barcelona', ....) -- not a capital
insert into guidebooks ('Edinburgh', ....) -- a capital
insert into guidebooks ('France', ....) -- fail

--
Andy Chambers

В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Cannot unsubscribe
Следующее
От: Richard Broersma
Дата:
Сообщение: Re: Table inheritance foreign key problem