How to have two not null constraints at the same time

Поиск
Список
Период
Сортировка
От A B
Тема How to have two not null constraints at the same time
Дата
Msg-id AANLkTikZm8HNYzDozuMbGtzYVoNopbY-Q_LHKWYbmc_+@mail.gmail.com
обсуждение исходный текст
Ответы Re: How to have two not null constraints at the same time  (Andreas <maps.on@gmx.net>)
Список pgsql-novice
Hi.
If I have a table

country (id int Primary key, president bigint references people);

and a table
people (id bigint, country_id int not null references country );

and now I want to enforce that there is a president in each country by
adding a not null constraint on the  column presient in the country
table.

Is there a way to do that? just adding the not null, will that not
get me into a chicken-egg situation where I can not add a country
without adding a president to the people table, which requires a
country... and so on.

So how would you insert the rows?


Or are there other ways to do this without creating a new table to
contain the presidents?

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

Предыдущее
От: Nima Ghorbany
Дата:
Сообщение: Integrity Error
Следующее
От: Andreas
Дата:
Сообщение: Re: How to have two not null constraints at the same time