Re: postgresql table inheritance

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: postgresql table inheritance
Date: 2007-11-30 14:20:57
Message-ID: 20071130142057.GF27784@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Nov 30, 2007 at 09:42:53PM +0800, Lincoln Yeoh wrote:
> Found this post on Slashdot which I found interesting, any comments?

I think this person is slightly confused.

> Table inheritence doesn't even make sense. Tables are analogous to
> relations.
> All relations are the same type, the relation type (think "set" or "array"
> to
> make it easier). How can one value of a type (one table) be a subtype of
> another value (another table)?

Easy, by having the columns of one table be a subset of the columns or
another table. Perhaps someone should point out an example, like a
table with "people" and subtables "employees" and "customers". The
subtables share the columns of the parent tables. This is nothing that
any OO language doesn't do.

> The correct way to store types and subtypes in the database is to store them
> in the columns. In other words, choose attribute VALUES from a TYPE SYSTEM.
> Nothing else in the relational model needs to be changed. Something like
> this, in hypothetical SQL-like language:

His example is a little wierd, but it is possible:

test=# create type foo as (a text, b text);
CREATE TYPE
test=# create table test( id int4, vals foo );
CREATE TABLE
test=# insert into test values ( 4, ROW('a', 'b'));
INSERT 0 1
test=# select * from test;
id | vals
----+-------
4 | (a,b)
(1 row)

The syntax is different but the ideas are there...

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
> -- John F Kennedy

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Cedric Boudin 2007-11-30 14:26:02 scrollable cursor in functions
Previous Message Lincoln Yeoh 2007-11-30 13:57:18 Re: Linux v.s. Mac OS-X Performance