Re: inheritance

From: chester c young <chestercyoung(at)yahoo(dot)com>
To: sql pgsql <pgsql-sql(at)postgresql(dot)org>
Subject: Re: inheritance
Date: 2007-03-08 20:25:07
Message-ID: 437880.34674.qm@web54303.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> --- Greg Toombs <greg(dot)toombs(at)bluebottle(dot)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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Shane Ambler 2007-03-08 21:46:37 Re: inheritance
Previous Message Richard Broersma Jr 2007-03-08 20:05:05 Re: A form of inheritance with PostgreSQL