Re: Need help with 'unique parents' constraint

From: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Need help with 'unique parents' constraint
Date: 2005-09-12 18:02:34
Message-ID: 200509122002.34864.leif@solumslekt.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Sunday 11 September 2005 16:04, Greg Sabino Mullane wrote:

> Not just old-fashioned, it's the biological law! (among homo sapiens
> anyway). I'd approach this with a trigger, as you can do complex
> checks and get back nice customized error messages. A sample script
> follows. Hard to tell without seeing your whole schema, but I see no
> need for a relation_id primary key if you already have a unique
> constraint on child_fk and parent_fk, so I made those into the
> primary key for the relations table:

Thank you for an excellent answer. I think I will have to study your
code for a while. But is it such a bad idea to have a separate column
for the primary key here? I see that there are two schools on this,
with diametrically opposed views. For my own part, I feel that it at
least doesn't hurt to have a surrogate key. Secondly, a single key
value is easier to reference from another table than a composite key.
--
Leif Biberg Kristensen
http://solumslekt.org/

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Fuhr 2005-09-12 23:03:23 Re: refer a column as a varible name?
Previous Message Wei 2005-09-12 18:01:08 How do I convert an integet to a timestamp?