Re: child fk problem - Mailing list pgsql-novice

From Oliver Elphick
Subject Re: child fk problem
Date
Msg-id 1133447581.17444.6.camel@braydb.bray-healthcare.com
Whole thread Raw
In response to child fk problem  ("Luis Silva" <lfs12@hotmail.com>)
List pgsql-novice
On Wed, 2005-11-30 at 18:45 +0000, Luis Silva wrote:
> I there, I'm trying to work with postgre, but i'm having a problem
> with inherits. I have a table (parent) that as an fk to another table.
> When i create a child,  i loose the connection to the other table. i
> dont need to insert values in the parent table. what do i need to do??
> tks in advance

With the current implementation of inheritance, you have to have a
separate table of keys in the inheritance hierarchy:

   CREATE TABLE keys (id INTEGER PRIMARY KEY);

   CREATE TABLE parent (id INTEGER PRIMARY KEY REFERENCES keys(id),
                        ...
                       );

   CREATE TABLE child (id INTEGER PRIMARY KEY REFERENCES keys(id),
                        ...child columns...
                       ) INHERITS parent;

Then set up triggers to insert a key into keys if a new key is inserted
in any table in the hierarchy and to delete from keys when a record is
deleted from the hierarchy.

Then any other table that needs to reference the hierarchy should
reference keys instead.

Oliver Elphick



pgsql-novice by date:

Previous
From: Marcus Engene
Date:
Subject: Re: Combinatorial problem
Next
From: Charley Tiggs
Date:
Subject: Re: Error