How to have two not null constraints at the same time

From: A B <gentosaker(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: How to have two not null constraints at the same time
Date: 2010-11-01 12:44:56
Message-ID: AANLkTikZm8HNYzDozuMbGtzYVoNopbY-Q_LHKWYbmc_+@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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?

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Andreas 2010-11-01 16:10:04 Re: How to have two not null constraints at the same time
Previous Message Nima Ghorbany 2010-11-01 07:03:55 Integrity Error