X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B7B6CD1B196 for ; Fri, 25 Jun 2004 11:18:05 -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 27470-02 for ; Fri, 25 Jun 2004 14:18:08 +0000 (GMT) Received: from web11.manitu.net (web11.manitu.net [217.11.48.111]) by svr1.postgresql.org (Postfix) with ESMTP id 2014DD1B19F for ; Fri, 25 Jun 2004 11:18:03 -0300 (ADT) Received: from [192.168.0.1] (dsl-082-082-213-239.arcor-ip.net [82.82.213.239]) (authenticated) by web11.manitu.net (8.10.2-SOL3/8.10.2) with ESMTP id i5PEHva29768; Fri, 25 Jun 2004 16:17:57 +0200 Subject: Re: question about which column(s) are the right foreign key From: Markus Bertheau To: Josh Berkus Cc: pgsql-sql@postgresql.org In-Reply-To: <200406202157.57676.josh@agliodbs.com> References: <1087766532.2660.27.camel@teetnang> <200406202157.57676.josh@agliodbs.com> Content-Type: text/plain; charset=UTF-8 Message-Id: <1088173080.3189.8.camel@teetnang> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Fri, 25 Jun 2004 16:18:01 +0200 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/261 X-Sequence-Number: 18206 =D0=92 =D0=9F=D0=BD=D0=B4, 21.06.2004, =D0=B2 06:57, Josh Berkus =D0=BF=D0= =B8=D1=88=D0=B5=D1=82: > Markus, >=20 > > I have objects in my database, and they have an object id generated with > > a sequence. Then I have object versions. The ids of object versions need > > to be unique only within one object id. But for simplicity they're > > generated with a sequence, too. > > > > Now I want to reference an object version. I can use just the object > > version id, because it "happens" to be globally unique. Conceptually > > though, I should use the object's id and its version's id. > > > > Now redundancy is Not Good=E2=84=A2, so I wonder which way is the Right= One=E2=84=A2. > > >=20 > Well, conceptually, you should have generated a numerical version id for = each=20 > object version which would have told you the sequence in which that versi= on=20 > was created, i.e. version #1 of object 23421, version #2 of object 23421,= =20 > etc. This can be automated a number of ways, although it does require=20 > locking the object during a version save. >=20 > The problem with the setup you have now is that you have an Object ID, wh= ich=20 > doesn't intrinsically mean anything, and an Object Version ID, which also= =20 > doesn't tell you anything about the object or the version. If you want = to=20 > keep information about which "edition" of an object this particular=20 > object-version is, you'll have to add a column -- which will then make th= e=20 > object-version id redundant, since the table will then have two keys. >=20 > That's "the Right One=E2=84=A2" Thanks. That really did provide the neccessary insight. --=20 Markus Bertheau