X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 2A7B5D81C2 for ; Mon, 12 Sep 2005 15:02:44 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 06958-08 for ; Mon, 12 Sep 2005 18:02:38 +0000 (GMT) Received: from mail43-s.fg.online.no (mail43-s.fg.online.no [148.122.161.43]) by svr1.postgresql.org (Postfix) with ESMTP id 9FF84D7AB7 for ; Mon, 12 Sep 2005 15:02:37 -0300 (ADT) Received: from [192.168.0.57] (062016183238.customer.alfanett.no [62.16.183.238]) by mail43.fg.online.no (8.12.11/8.12.11) with ESMTP id j8CI2Z6c022039 for ; Mon, 12 Sep 2005 20:02:35 +0200 (CEST) From: "Leif B. Kristensen" To: pgsql-sql@postgresql.org Subject: Re: Need help with 'unique parents' constraint Date: Mon, 12 Sep 2005 20:02:34 +0200 User-Agent: KMail/1.8.1 References: <7a5b3f3e2ddebaeda6d9df07ebca943a@biglumber.com> In-Reply-To: <7a5b3f3e2ddebaeda6d9df07ebca943a@biglumber.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200509122002.34864.leif@solumslekt.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.085 required=5 tests=[AWL=0.085] X-Spam-Level: X-Archive-Number: 200509/132 X-Sequence-Number: 22679 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/