Re: exploiting features of pg to obtain polymorphism

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
Cc: "PostgreSQL General ((EN))" <pgsql-general(at)postgresql(dot)org>
Subject: Re: exploiting features of pg to obtain polymorphism
Date: 2006-10-13 16:13:01
Message-ID: 1160755981.31966.196.camel@dogma.v10.wvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roman Neuhauser 2006-10-13 16:30:39 Re: more anti-postgresql FUD
Previous Message Tom Lane 2006-10-13 16:04:02 Re: UTF-8