postgresql table inheritance

From: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
To: pgsql-general(at)postgresql(dot)org
Subject: postgresql table inheritance
Date: 2007-11-30 13:42:53
Message-ID: 200711301348.lAUDmOQS058274@smtp9.jaring.my
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Found this post on Slashdot which I found interesting, any comments?

--- post follows ---
by Anonymous Coward on Wed Nov 28, '07 03:23 PM (#21509173)

Speak for your database -- postgresql does.

Postgresql's "table inheritance" is a flawed concept and has nothing to do
with the *type system*. Relations contain tuples, and tuples contain
attributes, which are a name plus a VALUE. Those values are chosen from TYPES
(sets of possible values). Those types are the TYPE SYSTEM.

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)? That's like saying, "3" is a subtype of "5",
if your types are integers. What if you use the expression "3+2" Is that "5"
still the subtype of 3? likewise, when you make complex queries with a "base"
table, does the result have any connection with the "sub" table? It's like
gobbledygook, just mashing words together without any understanding. That's
why the postgresql table inheritance concept doesn't see more widespread use.
Many people quickly discover the limitations (and incorrectly think it's just
"unfinished", when it actually is flawed).

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:

CREATE TABLE People ( INT id, PERSON_CLASS person )

p1 = PERSON_CLASS.new(name: "joe", etc)

p2 = CUSTOMER_CLASS.new(name: "bob", etc) // assume CUSTOMER_CLASS
subclass of PERSON_CLASS

INSERT INTO People VALUES (1, p1), (2, p2)

SELECT person FROM People WHERE person.name = "bob"

SELECT person, order FROM People JOIN Orders // can't do this in the
typical "object database"

This is a "solved problem" (see "The Third Manifesto"). It's just a matter of
getting somebody to implement it. But the vendors are clueless, thinking
object databases are a "different model" and not wanting to confuse
programmers, and programmers are clueless, not even understanding SQL or
types and values half the time, so they don't demand anything new from
vendors... we never move forward.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Shane Ambler 2007-11-30 13:50:09 Re: 1 cluster on several servers
Previous Message Thomas Kellerer 2007-11-30 13:33:23 Re: PostgresSQL vs Ingress