Re: child fk problem

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Luis Silva <lfs12(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: child fk problem
Date: 2005-12-01 14:33:01
Message-ID: 1133447581.17444.6.camel@braydb.bray-healthcare.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Charley Tiggs 2005-12-01 15:50:15 Re: Error
Previous Message Paulo Jorge Matos 2005-12-01 09:54:53 PgSQL Initial Questions (before starting project)