pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Foreign Keys and Inheritance
2+ messages / 2 participants
[nested] [flat]

* Foreign Keys and Inheritance
@ 2001-06-01 15:38  Dennis Muhlestein <dennis@zserve.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Dennis Muhlestein @ 2001-06-01 15:38 UTC (permalink / raw)
  To: pgsql-general@postgresql.org.pgsql-sql


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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [SQL] Foreign Keys and Inheritance
@ 2001-06-06 15:54  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: Dennis Muhlestein <dennis@zserve.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Stephan Szabo @ 2001-06-06 15:54 UTC (permalink / raw)
  To: Dennis Muhlestein <dennis@zserve.com>; +Cc: pgsql-general@postgresql.org; pgsql-sql


Currently you can't do that.  Foreign keys are only referencing the
explicitly named tables.  This will probably change around the time
that someone goes in and does alot of work on inheritance.  BTW:
primary keys (and unique) also do not inherit.

On Fri, 1 Jun 2001, Dennis Muhlestein wrote:

> 
> 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.




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-06-06 15:54 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-01 15:38 Foreign Keys and Inheritance Dennis Muhlestein <dennis@zserve.com>
2001-06-06 15:54 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>

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