Re: inheritance - Mailing list pgsql-sql

From chester c young
Subject Re: inheritance
Date
Msg-id 437880.34674.qm@web54303.mail.yahoo.com
Whole thread Raw
In response to inheritance  (Chris Bitmead <chris@tech.com.au>)
Responses Re: inheritance  (Shane Ambler <pgsql@Sheeky.Biz>)
List pgsql-sql
> --- Greg Toombs <greg.toombs@bluebottle.com> wrote:
>
>
> I'm trying to figure out how to nicely implement a C++
class-likesystem > > with PostgreSQL. Consider the following:
> 
> Tables Fruit, Apple, Orange

you can do this traditionally or through pg inheritance, although I do
not think inheritance is well supported before 8.2.

from years of experience the easiest approach and aesthetically the
least satisfying approach is to put everything into the fruit table

create table fruit( fruit_id  integer primary key, fruit_tp  varchar(12), ...
);

with this approach you simply deal with whatever column's your
interested in - with apples the orange specific columns are dead wood -
they don't get in the way and take up no storage - you just need to
learn to ignore them, maybe using views to help.

you can have a fruit table plus apple and orange tables.

create table fruit( fruit_id integer primary key, <common attributes>
)

create table apple( apple_id integer primary key, fruit_id integer not null references fruit, <apple attributes>
)

you then need to build views to join fruit with apple and oranges,
because some of the apple attributes are in the fruit table.

lastly you need to handle dml.  for example, when you insert an apple
you need to insert into the fruit and the apple table.  this can be
done either through your application bracketing your dml with a begin
and commit, or can be done through rules (much, much cooler) (the doc
on rules will hold your hand through this).


____________________________________________________________________________________
Finding fabulous fares is fun.  
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097


pgsql-sql by date:

Previous
From: Richard Broersma Jr
Date:
Subject: Re: A form of inheritance with PostgreSQL
Next
From: Shane Ambler
Date:
Subject: Re: inheritance