Re: Using a serial primary key as a foreign key in a second table - Mailing list pgsql-novice

From Richard Broersma Jr
Subject Re: Using a serial primary key as a foreign key in a second table
Date
Msg-id 610820.38154.qm@web31813.mail.mud.yahoo.com
Whole thread Raw
In response to Re: Using a serial primary key as a foreign key in a second table  (Sean Davis <sdavis2@mail.nih.gov>)
List pgsql-novice
> Actually, your explanation of the problem is very succinct.  Postgresql offers
> a direct solution to situations like these.  See here:
>
> http://www.postgresql.org/docs/8.2/interactive/ddl-inherit.html
>
> Isn't postgresql an AWESOME product!

Not arguments here, but there is one point of caution with postgresql's table inheritance that
should be considered in during schema design.  You cannot use the parent's tables primary key as a
foreign key in other parts of the schema, since the parent table does not >actually< have records
inserted into the child tables.

I have worked out an inheritance solution that does allow this just by using regular tables linked
with foreign keys.  To handle simultaneous insertion and updates across an entire branch of the
hierarchy I used a view made updatable using the rule system.  For deletes I just create the child
tables using cascade deletes.

The advantage using postgresql's tables inheritance is that it is quite easy to set up and it
works very well.  The solution I am using requires alot more planning and setup. :o(

If any are interested I can provide more details on how this is accomplished.

Regards,

Richard Broersma Jr.

pgsql-novice by date:

Previous
From: Sean Davis
Date:
Subject: Re: Using a serial primary key as a foreign key in a second table
Next
From: Bruno Wolff III
Date:
Subject: Re: Using a serial primary key as a foreign key in a second table