pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: pgsql-sql@postgresql.org
Subject: Re: Inheritance - Multiple membership
Date: Wed, 13 Jun 2001 09:56:33 -0700
Message-ID: <web-71438@davinci.ethosmedia.com> (raw)
In-Reply-To: <FB93404FB67ED311ABF9009027991188417E66@www.ehso.emory.edu>

Jimmie,

> Say I have a tbl_person. tbl_teacher and tbl_student both inherit
> from
> tbl_person and each have their own extended attributes. Is it
> possible for
> a person in tbl_person to be both a teacher at the school, and also a
> student (say night school or something). Also, the student may be a
> part-time employee, like a graduate student. If it is possible, what
> would
> an insert look like. Given the possibility that someone can exist in
> both
> tbl_teacher and tbl_student, what happens if you delete their student
> record. I'm guessing that it should leave the other records in tact.

IMHO, inheritance is *not* the way to do this. What you want
relationally is three tables:

tbl_people
tbl_student_attributes
tbl_teacher_attributes

Then you can define two views:

vw_students
tbl_people JOIN tbl_student_attributes

vw_teachers
tbl_people JOIN tbl_teacher_attributes

This way, if a student's teaching assignment ends, you can delete her
teacher_attributes while keeping her in the system as a studnet;
contrawise, if she quits the institution, you can delete her record in
tbl_people and remove her from the system. 

Further, by defining the triggers to make the views updatable, you can
treat them as if they were tables ... e.g. "UPDATE vw_students WHERE
..." This allows you to maintain perfect relational integrity while
dealing with the fact that a few individuals are both students and
teachers.

Fabian Pascal has a whole chapter about how properly designed relational
structures make inheritance unnecessary or even hazardous ... see
"Practical Issues in Database Design."

-Josh Berkus

P.S. hey, Tom, do you think that simple views can be made automatically
updatable by default someday? version 8.0?


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



view thread (2+ messages)

Message-ID: <web-71438@davinci.ethosmedia.com>
Permalink:  ../web-71438@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-71438@davinci.ethosmedia.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com
  Subject: Re: Inheritance - Multiple membership
  In-Reply-To: <web-71438@davinci.ethosmedia.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox