Subject: Re: Using object IDs to link objects

From: [email-masked] (Kai Petzke)
Date: Tue, 4 Jan 94 0:00:58 MET

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

---

From: [email-masked] (Alan Vayda)
Date: Mon, 3 Jan 94 12:21:51 EST

The difficulty is with the mechanics of creating the instances with
append commands.  I don't know how to collect the OIDs so that they
can be stored in the related instances.  

Alan Vayda
[email-masked]
ERIM
PO Box 134001
Ann Arbor, MI 48113-4001