Re: foreign keys constraints, depending on each other

From: Marc SCHAEFER <schaefer(at)alphanet(dot)ch>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: foreign keys constraints, depending on each other
Date: 2001-06-11 08:25:45
Message-ID: Pine.LNX.3.96.1010611102205.977A-100000@defian.alphanet.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 10 Jun 2001 zilch(at)home(dot)se wrote:

> I was about the create 3 tables, namely mother, father and child. Mother has
> a foreign key pointing at father ( id ), and father has a foreign key
> pointing at mother ( id ). Child has one pointer to mother ( id ) and one
> pointer to father ( id ). How can I prevent the error message from occurring?

Personnally, I tend to avoid those circular references in any computing
field.

I would remove the father and mother references, and add a
is_married
relation; as a table, with a UNIQUE(father_id), UNIQUE(mother_id)
constraint (a person can be only married once).

I would keep the direct references from child.

It might a bit diminush the performance, but circular references are a
pain to handle.

Alternatively, keep only the mother -> father reference, and determine the
wife of father through query like:

SELECT m.id FROM mother m WHERE m.father_id = ?

This can be quite efficient if the mother was looked up previously anyway.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mario Weilguni 2001-06-11 09:47:34 Re: foreign keys constraints, depending on each other
Previous Message Martín Marqués 2001-06-11 08:19:31 ORDER BY what?