Re: inheritance

From: Shane Ambler <pgsql(at)Sheeky(dot)Biz>
To: chester c young <chestercyoung(at)yahoo(dot)com>
Cc: sql pgsql <pgsql-sql(at)postgresql(dot)org>, greg(dot)toombs(at)bluebottle(dot)com
Subject: Re: inheritance
Date: 2007-03-08 21:46:37
Message-ID: 45F0843D.5020407@Sheeky.Biz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

chester c young wrote:
>> --- 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.

Inheritance will most likely fit your C++ class-like system better and
will not need foreign keys. Inheritance has been available in postgresql
for many years and I think you will find it quite stable. (Not sure if
pg6.x had it but it was available in 7.x) Historically a Table in
postgresql was called a class (pre-sql) which is still reflected in the
system catalogs with pg_class containing the list of tables and other
classes like indexes....

http://www.postgresql.org/docs/8.2/interactive/ddl-inherit.html

You would then have table fruit as your base class and table oranges
that inherits from fruit, giving it all the columns that fruit has plus
any that are added to table oranges as well.

selecting from table fruit will allow you to get all rows from table
apples and table oranges but not the columns unique to the apples or
oranges tables.

Maybe then you'll add a table basket that has a foreign key to the fruit
table....... ;-)

--

Shane Ambler
pgSQL(at)Sheeky(dot)Biz

Get Sheeky @ http://Sheeky.Biz

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma Jr 2007-03-08 22:11:53 Re: inheritance
Previous Message chester c young 2007-03-08 20:25:07 Re: inheritance