Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2002
    Posts
    173

    Unanswered: postgresql linked / split table

    I'd like to split a table into 2 different tables. I want to link them using the primary key. For example: primary key in table1 will link to primary key in table 2. I believe I would setup some kind of foreign key for this. I'm wondering how I can have the system automatically create the record in table2 when a record is added in table1. (it would be a 1 to 1 relationship)

  2. #2
    Join Date
    Apr 2003
    Posts
    23
    Simply by using trigger or rules on a view.

  3. #3
    Join Date
    Jun 2002
    Posts
    173
    I'm noob to postgresql so I'm not quite sure how to setup the trigger. This is what I'd like to do.

    table1 - has all the main contact info

    These tables have relavent info depending on the contact type in table1
    tablea
    tableb
    tablec
    tabled


    If the contact type is "A" in table1, upon creating a new record I need a new record to be created in tablea.

    If the contact type is "B" in table1, upon creating a new record I need a new record to be created in tableb.

    I'm using pgadminIII as well as EMS to manage my postgresql database and can see how to add the trigger but I just don't know the programming in order to do it.

  4. #4
    Join Date
    Jun 2004
    Posts
    31
    This might be a good place to use inheritance. I never thought this was much use until I read your post.

    Inheritance lets you do exactly this.

    Create table 1 with the common fields.
    Create table A, inheriting table 1, along with additional fields.
    Create table B, inheriting table 1, along with additional fields,
    Etc.

    Simply insert the appropriate record into A, B, C, etc.

    Only insert into table 1 if a record won't fit anywhere else.

    If you want to see all of the records, just select * from table 1, and you will see all of the records from 1, A, B, C and so on.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •