Return-Path: owner-postman
Received: from localhost (localhost [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id PAA29261 for postgres-dist; Mon, 3 Jan 1994 15:26:02 -0800
Resent-From: POSTGRES mailing list <postman@postgres.Berkeley.EDU>
Resent-Message-Id: <199401032326.PAA29261@nobozo.CS.Berkeley.EDU>
X-Authentication-Warning: nobozo.CS.Berkeley.EDU: Host localhost didn't use HELO protocol
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: owner-postman
Received: from mailgzrz.TU-Berlin.DE (mailgzrz.TU-Berlin.DE [130.149.4.10]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id PAA29246 for <postgres@nobozo.CS.Berkeley.EDU>; Mon, 3 Jan 1994 15:25:24 -0800
Received: from marie.physik.TU-Berlin.DE by mailgzrz.TU-Berlin.DE (5.65c/ZRZ-MX)
          for <postgres@nobozo.CS.Berkeley.EDU>
	  id AA01756; Tue, 4 Jan 1994 00:25:05 +0100
Received: by marie.physik.tu-berlin.de (5.65c8/SMI-SVR4)
	id AA03568; Tue, 4 Jan 1994 00:25:04 +0100
Message-Id: <199401032325.AA03568@marie.physik.tu-berlin.de>
Subject: Re: Using object IDs to link objects
To: vayda@erim.org (Alan Vayda)
Date: Tue, 4 Jan 94 0:00:58 MET
From: wpp@marie.physik.tu-berlin.de (Kai Petzke)
Cc: postgres@postgres.Berkeley.EDU
In-Reply-To: <9401031721.AA21673@csd630a.erim.org>; from "Alan Vayda" at Jan 3, 94 12:21 pm
X-Mailer: ELM [version 2.3 PL11]
Content-Type: text
Content-Length: 1896
Resent-To: postgres-dist@postgres.Berkeley.EDU
Resent-Date: Mon, 03 Jan 94 15:26:02 -0800
Resent-XMts: smtp

Hi,

first of all:  I wish a Happy New Year to all Postgres people!


> 
> I'm relatively new to POSTGRES and would like some suggestions on the
> use of object ID's for linking class instances together. 
> Here is a simplified version of my problem:
> 
> I have two classes, for example a book class and a page class.
> Each book instance is related to a number of page instances.
> I need to determine the related book instance from a page instance and
> all of the related page instances from a book instance.
> It seems that all that is required is to do one of the following:
> 1. add a list of page instance OIDs to each book instance
> 2. add a book instance OID to each page instance

The way to go is 2.

However, I would recommend not to depend on database internals
such as Object ID (Postgres) or Row ID (many commercial ones)
at all.  Instead, try to use an unequivocal attribute of the
book class for referencing the book.  That could be the ISBN
number, or the book title.

To go for an example:

	create book (title = text, isbn = text) \g
	create page (content = text, number = int4, title = text) \g

	append book (title = "A long false story", isbn = "3-349-239-129") \g
	append page (content = "In winter 1962, Mr John F Link came back ...",
		     number = 1, title = "A long false story") \g

If you want to stay with the OID's, though, try the following:

create book (title = text, isbn = text) \g
create page (text = text, number = int4, book = oid) \g

	append book (title = "A long false story", isbn = "3-349-239-129") \g
	append page (text = "In winter 1962, Mr John F Link came back ...",
		     number = 1,
		     book = book.oid)
		where book.title = "A long false story"

This appends the new page to any book, which has the title "A long false
story".  It requires one database lookup per appended page, so it may
be real slow when appending a lot of data.

Kai

