Re: exploiting features of pg to obtain polymorphism - Mailing list pgsql-general

From Jeff Davis
Subject Re: exploiting features of pg to obtain polymorphism
Date
Msg-id 1160755981.31966.196.camel@dogma.v10.wvs
Whole thread Raw
In response to exploiting features of pg to obtain polymorphism maintaining ref. integrity  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
List pgsql-general
On Fri, 2006-10-06 at 23:09 +0200, Ivan Sergio Borgonovo wrote:
> Is there any good documentation, example, tutorial, pamphlet, discussion... to exploit pg features to obtain
"polymorphic"behavior without renouncing to referential integrity? 
>
> Inheritance seems *just* promising.
>
> Any methodical a approach to the problem in pg context?
>

I'm not sure if this answers your question, but here's how I do
inheritance in the relational model.

Just make a "parent" table that holds a more generic object like:

CREATE TABLE person (name TEXT PRIMARY KEY, age INT, height NUMERIC);

Then a "child" table like:

CREATE TABLE student (name TEXT REFERENCES person(name), gpa NUMERIC);

Every person, student or otherwise has a record in "person". If, and
only if, they are a student they have a record in the "student" table.

To select all people, select only from the "person" table. To select all
students, select from the join of the two tables.

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: UTF-8
Next
From: "Brian J. Erickson"
Date:
Subject: Re: PostgreSQL Database Transfer between machines(again)