Thread: inheritance

inheritance

From
"Felipe Schnack"
Date:
  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??

Felipe Schnack
Analista de Sistemas
felipes@ritterdosreis.br
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
felipes@ritterdosreis.br
Fone/Fax.: (51)32303328


Re: inheritance

From
Oliver Elphick
Date:
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