Thread: Inheritance referential integrity problem

Inheritance referential integrity problem

From
Petru Paler
Date:
Hello everyone,


I'm using Postgresql's very nice inheritance support in a project, but I
just stumbled upon a problem that I'm not sure how to fix (or whether it's
my problem or postgresql's).

Here is a small set of tables that can be used to reproduce the problem:

create table a (id integer primary key);
create table b (foo varchar(100)) inherits(a);
create table c(id integer primary key, b_id integer references a(id));

The data:

test=# insert into b(id, foo) values (1, 'asd');
INSERT 19991 1
test=# select * from b;
 id | foo
----+-----
  1 | asd
(1 row)

test=# select * from a;
 id
----
  1
(1 row)


And the problem:

test=# insert into c (id, b_id) values (5, 1);
ERROR:  <unnamed> referential integrity violation - key referenced from c
not found in a

Could someone enlighten me on what I'm missing? Why is the constraint not
satisfied, since the key is clearly present in a? If that row is
considered to belong to b, then why does it show up in a?


If possible, please Cc me on the responses as I'm not subscribed to this
mailing list.


Thank you,
Petru


Re: Inheritance referential integrity problem

From
Stephan Szabo
Date:
On Tue, 2 Apr 2002, Petru Paler wrote:

> I'm using Postgresql's very nice inheritance support in a project, but I
> just stumbled upon a problem that I'm not sure how to fix (or whether it's
> my problem or postgresql's).
>
> ERROR:  <unnamed> referential integrity violation - key referenced from c
> not found in a
>
> Could someone enlighten me on what I'm missing? Why is the constraint not
> satisfied, since the key is clearly present in a? If that row is
> considered to belong to b, then why does it show up in a?

The references constraints currently reference only the particularly
named table and not any children.  Selects by default show rows in the
children tables (you can use ONLY to not get this behavior:
"select * from ONLY a;") It's one of the limitations of the current
implementation.