Thread: child fk problem

child fk problem

From
"Luis Silva"
Date:
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

Re: child fk problem

From
Jaime Casanova
Date:
On 11/30/05, Luis Silva <lfs12@hotmail.com> 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

You can read the manual...

of special interest to you could be the inheritance section (and read
the caveats):
http://www.postgresql.org/docs/8.1/static/ddl-inherit.html

--
regards,
Jaime Casanova
(DBA: DataBase Aniquilator ;)

Re: child fk problem

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