Fw: object features of PostgreSQL
This is a really interesting message found on the Byte magazine discussions for anyone who ever thought about implimenting a Postgres storage for Zope. -Michel robin <robin@nospam.org> wrote in message news:<7u0kr7$st4$1@cmpweb-media0.web.cerf.net>...
Jon Udell <udell@monad.net> wrote in message news:380367CF.7AAB0D90@monad.net...
What features does DB2 have which make it an ODBMS?
I'm not sure.
But...can you tell us more about the object features of PostgreSQL,
and
how you're using them?
Jon Udell
PostgreSQL adds an "inherits" clause to the CREATE TABLE statement, so an unimaginative example would be:
create table people ( forename text, surname text, initials text, email text );
create table staff ( office text, extension text ) inherits (people);
create table clients ( organisation oid ) inherits (people);
This would create three tables, people, with fields; forename, surname, initials, email, staff; with fields forename, surname, initials, email, office and extension, and clients; with fields forename, surname, initials, email and organisation.
Queries can then be made on any of the tables individually in the normal way, but also using an extension syntax:
select * from table people*;
Which would query table people, and all tables which inherit from it. In fact the Postgres documentation makes reference to "classes" instead of tables. Clearly a query such as this can only return the fields which are common to all of the tables in the hierarchy, i.e. the fields of the base class.
I have used this feature with Perl to implement a simple object persistence veneer above DBI. I create a base class called object to start the hierarchy;
create table object (class text default 'object');
and then further classes are like this;
create table people (class text default 'people', forename text, surname text, initials text, email text );
etc.
The "class text default '<class name>'" field results in every row having the name of the table it was entered into associated with it. PostgreSQL also assigns a unique OID to every row in the database, so using the people example, I can do "select *,oid from people*", retrieve the results using fetchrow_hashref and then bless the rows with the contents of their own class field.
The result is a list of perl objects, each of the appropriate type. The perl classes can in turn inherit from a base dbobject class which can generate the correct insert code automatically.
This is how I handled object persistence in a number of web based applications for written for clients of my previous employer. I've changed jobs, and expect to be working in Java, probably with DB2 and Websphere. I know little about DB2, except that it's been called an "ORDBMS", and I wondered what the term is referring to.
--
-Robin Barooah robin(at)sublime.org
Interesting forward, Michel. The object features of PostgreSQL are suffering from a little bit of neglect, since none of the current developers use them or are focussed on them. Recently, items have been added to the TODO list to fix up some missing functionality with respect to which DDL commands will accept the class notation, and well as some discussion as to what should and shouldn't be inherited, and how to do it (for example, unique indices on a field in a parent table, which is inherited by the children) A large scale project, like a db store for Zope, would certainly exercise that codebase, and flush out all the moths (exorcise them?) The few mentions I've seen on the PostgreSQL lists seem to indicate the the existing code works, but is missing a few pieces. Perhaps a semester coding project for some student around here ... Ross -- Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> NSBRI Research Scientist/Programmer Computer and Information Technology Institute Rice University, 6100 S. Main St., Houston, TX 77005
participants (2)
-
Michel Pelletier -
Ross J. Reedstrom