Thread: FK to inherited table, referential integrity violation

FK to inherited table, referential integrity violation

From
yacht@seznam.cz
Date:
Is it bug?

CREATE TABLE base ( base INT PRIMARY KEY );
CREATE TABLE child ( val INT ) INHERITS ( base );
CREATE TABLE ref (
      atr INT
    , base INT REFERENCES base ON UPDATE cascade ON DELETE cascade );

INSERT INTO child VALUES ( 1, 2 );

SELECT * FROM base;
 base
------
    1

SELECT * FROM child;
 base | val
------+-----
    1 |   2

INSERT INTO ref VALUES ( 3, 1 );

ERROR:  $1 referential integrity violation - key referenced from ref not
found in base

--
 oo  don't worry
\__/ be happy

Re: FK to inherited table, referential integrity violation

From
Stephan Szabo
Date:
On Wed, 20 Aug 2003 yacht@seznam.cz wrote:

> Is it bug?

Just an unimplemented feature. Foreign keys currently reference only
the named table and not any of the subtables.  Inheritance has some
serious limitations right now (for example, the primary key on base
doesn't inherit to child as well which means you can insert multiple
rows with the same key into child).  If you want the gory details, this
comes up every few months so there are lots of discussions in the
archives.