Re: exploiting features of pg to obtain polymorphism

Поиск
Список
Период
Сортировка
От Jeff Davis
Тема Re: exploiting features of pg to obtain polymorphism
Дата
Msg-id 1160755981.31966.196.camel@dogma.v10.wvs
обсуждение исходный текст
Ответ на exploiting features of pg to obtain polymorphism maintaining ref. integrity  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: UTF-8
Следующее
От: "Brian J. Erickson"
Дата:
Сообщение: Re: PostgreSQL Database Transfer between machines(again)