pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dennis Muhlestein <dennis@zserve.com>
To: pgsql-general@postgresql.org.pgsql-sql
Subject: Foreign Keys and Inheritance
Date: Fri, 1 Jun 2001 09:38:48 -0600
Message-ID: <9f8cu9$i29$1@news.tht.net> (raw)


If I have table A, which contains a primary key,
and table B which inherits from A.

How can I Create a Foreign Key on table C that references A, but will 
also pass if a record in inserted in to B.

for instance:

create table A
(
        prim_key char(20) not null primary key
);

create table B
(
) INHERITS A;


create table C
(
        data char(2) not null primary key,
        constraint fk_C FOREIGN KEY ( data ) REFERENCES A ( prim_key ) ON DELETE 
CASCADE ON UPDATE CASCADE
)



With this setup, my record must be inserted in to A or I'll get a 
referential integrity problem when I insert in to C.

I want to be able to insert in to A, B , or another table inherited from A, 
and have table C recognize that as it's foreign key.

Thanks



view thread (2+ messages)  latest in thread

Message-ID: <9f8cu9$i29$1@news.tht.net>
Permalink:  ../9f8cu9$i29$1@news.tht.net/
Also on:    postgresql.org/message-id/9f8cu9$i29$1@news.tht.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dennis@zserve.com, pgsql-general@postgresql.org.pgsql-sql
  Subject: Re: Foreign Keys and Inheritance
  In-Reply-To: <9f8cu9$i29$1@news.tht.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox