Re: inheritance

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Felipe Schnack <felipes(at)ritterdosreis(dot)br>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: inheritance
Date: 2003-02-16 20:47:25
Message-ID: 1045428445.30277.59.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 2003-02-13 at 12:04, Felipe Schnack wrote:
> Hi all...
> I'm starting to play with pgsql inheritance features and I just wondered a
> specific situation where I wouldn't have any idea of how to use it. Let's say
> I create these tables:
> create table persons (id serial primary key);
> create table students (number int) inherits persons;
> create table emplyees (anothernumber int) inherits persons;
> Let say I can have a person that is a student and is a employee of the
> company... how I would insert its data in my database??

You can create another table:
create table student_employees (PRIMARY KEY (id)) inherits
(students, employees);

Beware, that you have no overall uniqueness check on the id field; and
the primary key constraint is not inherited - it must be repeated for
each table.

On the other hand there may be better ways of solving this particular
problem, such as using foreign keys instead.

--
Oliver Elphick Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"But as many as received him, to them gave he power to
become the sons of God, even to them that believe on
his name" John 1:12

In response to

  • inheritance at 2003-02-13 12:04:02 from Felipe Schnack

Browse pgsql-general by date

  From Date Subject
Next Message Oliver Elphick 2003-02-16 20:55:58 Re: accessing currval(), How? ... Trigger? I think...???
Previous Message Dima Tkach 2003-02-16 20:37:17 Re: Index not used with IS NULL