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 B5D68D6F6F for ; Mon, 17 Oct 2005 14:00:52 -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 46408-07 for ; Mon, 17 Oct 2005 17:00:47 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 130D5D7940 for ; Mon, 17 Oct 2005 14:00:47 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 51EB7401CB2; Mon, 17 Oct 2005 18:00:21 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 4E5AC15ED9; Mon, 17 Oct 2005 17:57:56 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 27254-01; Mon, 17 Oct 2005 17:57:53 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 3290315ED5; Mon, 17 Oct 2005 17:57:53 +0100 (BST) Message-ID: <4353D810.2050606@archonet.com> Date: Mon, 17 Oct 2005 17:57:52 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en MIME-Version: 1.0 To: David Pradier Cc: codeWarrior , pgsql-sql@postgresql.org Subject: Re: Design problemi : using the same primary keys for inherited References: <20051014091829.GB19930@clarisys.fr> <20051017141353.GF19930@clarisys.fr> In-Reply-To: <20051017141353.GF19930@clarisys.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.059 required=5 tests=[AWL=0.009, FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/184 X-Sequence-Number: 23037 David Pradier wrote: > Well yes, i find your system very interesting and will maybe use it as > solution for another problem we have ( :-) ), but i fail to see where > it makes use of a primary key referencing another primary key ? As regards the issue of one primary-key referencing another, I can't see any problem. You want 0 or 1 references from table B to any row in table A - this does that without any fuss or complication. A primary key is a value (or set of values) like any other. It is unique over any one table, but nothing says it can't be the same as a value in some other table. The other way would be something like: CREATE TABLE A ( id serial not null unique, aval text, primary key (id) ); CREATE TABLE B ( id serial not null unique, aref int4 not null unique references A, bval text, primary key (id) ); So - in table B we now have two candidate keys (id, aref) and above I've chosen "id" as the primary-key. But I can eliminate "id" completely and not lose any of the meaning of table "B" - which tells me that I was wrong to think the rest of the table was dependent on "id". So, I must have been wrong in making "id" a primary-key and since it has no meaning of its own, I can eliminate it. CREATE TABLE B ( aref int4 not null unique references A, bval text, primary key (aref) ); -- Richard Huxton Archonet Ltd