From: Shane Ambler <pgsql@Sheeky.Biz>
To: chester c young <chestercyoung@yahoo.com>
Cc: sql pgsql <pgsql-sql@postgresql.org>
Cc: greg.toombs@bluebottle.com
Subject: Re: inheritance
Date: Fri, 09 Mar 2007 08:16:37 +1030
Message-ID: <45F0843D.5020407@Sheeky.Biz> (raw)
In-Reply-To: <437880.34674.qm@web54303.mail.yahoo.com>
References: <437880.34674.qm@web54303.mail.yahoo.com>
chester c young wrote:
>> --- 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.
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@Sheeky.Biz
Get Sheeky @ http://Sheeky.Biz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: pgsql@Sheeky.Biz, chestercyoung@yahoo.com, greg.toombs@bluebottle.com
Subject: Re: inheritance
In-Reply-To: <45F0843D.5020407@Sheeky.Biz>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox