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

Search Discussions

  • Jaime Casanova at Nov 30, 2005 at 7:51 pm

    On 11/30/05, 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
    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 ;)
  • Oliver Elphick at Dec 1, 2005 at 2:33 pm

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppgsql-novice @
categoriespostgresql
postedNov 30, '05 at 6:51p
activeDec 1, '05 at 2:33p
posts3
users3
websitepostgresql.org
irc#postgresql

People

Translate

site design / logo © 2022 Grokbase