Re: inheritance - Mailing list pgsql-general

From Oliver Elphick
Subject Re: inheritance
Date
Msg-id 1045428445.30277.59.camel@linda.lfix.co.uk
Whole thread Raw
In response to inheritance  ("Felipe Schnack" <felipes@ritterdosreis.br>)
List 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.Elphick@lfix.co.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


pgsql-general by date:

Previous
From: Dima Tkach
Date:
Subject: Re: Index not used with IS NULL
Next
From: Oliver Elphick
Date:
Subject: Re: accessing currval(), How? ... Trigger? I think...???