Re: [SQL] Foreign Keys and Inheritance

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Dennis Muhlestein <dennis(at)zserve(dot)com>
Cc: pgsql-general(at)postgresql(dot)org, pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Foreign Keys and Inheritance
Date: 2001-06-06 15:54:17
Message-ID: Pine.BSF.4.21.0106060852530.15539-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martín Marqués 2001-06-06 15:57:13 Re: [HACKERS] something smells bad
Previous Message Tim Barnard 2001-06-06 15:46:04 Re: form generator?

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2001-06-06 16:23:15 Re: audit trail and system catalogs
Previous Message Josh Berkus 2001-06-06 15:53:08 Re: seleting all dates between two dates