Skip site navigation (1) Skip section navigation (2)

root of parent-child table with NOT NULL constraint

From: bill(at)wadley(dot)org
To: pgsql-novice(at)postgresql(dot)org
Subject: root of parent-child table with NOT NULL constraint
Date: 2002-05-02 19:07:21
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

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

      Id INTEGER,
      ParentId INTEGER
         CONSTRAINT ParentId_Constraint NOT NULL REFERENCES Groups(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 by date

Next:From: Terrence BrannonDate: 2002-05-02 21:09:01
Subject: Re: non-root installation of Postgresql?
Previous:From: P. JourdanDate: 2002-05-02 18:38:32
Subject: Re: error messages

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group