Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 799BC9FC00E for ; Thu, 8 Mar 2007 17:46:56 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 53648-08 for ; Thu, 8 Mar 2007 17:46:42 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by postgresql.org (Postfix) with ESMTP id 95F0A9FBEB7 for ; Thu, 8 Mar 2007 17:46:42 -0400 (AST) Received: from ppp247-71.static.internode.on.net (HELO [192.168.8.200]) ([203.122.247.71]) by ipmail02.adl2.internode.on.net with ESMTP; 09 Mar 2007 08:16:40 +1030 X-IronPort-AV: i="4.14,264,1170595800"; d="scan'208"; a="95159006:sNHT51105068" Message-ID: <45F0843D.5020407@Sheeky.Biz> Date: Fri, 09 Mar 2007 08:16:37 +1030 From: Shane Ambler User-Agent: Thunderbird 1.5.0.10 (Macintosh/20070221) MIME-Version: 1.0 To: chester c young CC: sql pgsql , greg.toombs@bluebottle.com Subject: Re: inheritance References: <437880.34674.qm@web54303.mail.yahoo.com> In-Reply-To: <437880.34674.qm@web54303.mail.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.052 tagged_above=0 required=5 tests=AWL, BAYES_50, BIZ_TLD, SPF_HELO_PASS X-Spam-Level: ** X-Archive-Number: 200703/86 X-Sequence-Number: 27724 chester c young wrote: >> --- Greg Toombs 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