root of parent-child table with NOT NULL constraint

Поиск
Список
Период
Сортировка
От bill@wadley.org
Тема root of parent-child table with NOT NULL constraint
Дата
Msg-id Pine.LNX.4.43.0205021357500.5681-100000@ensim.rackshack.net
обсуждение исходный текст
Ответы Re: root of parent-child table with NOT NULL
Список pgsql-novice
Hello!

I've created the following table that (I hope) represents groups that
have a relationship to their parent group:

   CREATE TABLE Groups
   (
      Id INTEGER,
      ParentId INTEGER
         CONSTRAINT ParentId_Constraint NOT NULL REFERENCES Groups(Id),
      CONSTRAINT Groups_PK PRIMARY KEY (Id)
   );

The question is: how do I add the first group? The very first group is
the root group, and doesn't have a parent.

My choices seem to be to either:

- create the table without the constraint, add a group that will be the
  parent of all "root" groups, then add the constraint. The problem with
  this solution seems to be that dump and restores will be problematic.

- remove the NOT NULL constraint altogether, but then I won't get the
  kind of referential integerity I want.

So, kind sirs/madams, what am I missing?

Thank you!

Bill Wadley


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

Предыдущее
От: "P. Jourdan"
Дата:
Сообщение: Re: error messages
Следующее
От: Terrence Brannon
Дата:
Сообщение: Re: non-root installation of Postgresql?