BUG #5495: RI/FK on self and inherited table

From: "Martin Edlman" <edlman(at)fortech(dot)cz>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #5495: RI/FK on self and inherited table
Date: 2010-06-09 08:01:48
Message-ID: 201006090801.o5981mVK028904@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 5495
Logged by: Martin Edlman
Email address: edlman(at)fortech(dot)cz
PostgreSQL version: 8.4.4
Operating system: Scientific Linux 5.5 (RHEL)
Description: RI/FK on self and inherited table
Details:

I have a table

net.device(id serial, parent_id integer null, name varchar(100), ip_address
inet, ...)
device_parent_id_fkey FOREIGN KEY (parent_id) REFERENCES net.device(id) ON
UPDATE CASCADE

and a table

net.computer(parent_id integer not null, ...) inherits (net.device);

I have a script which inserts records to both tables and it always stops on
the same record for net.computer with followin message

ERROR: insert or update on table "device" violates foreign key constraint
"device_parent_id_fkey"
DETAIL: Key (parent_id)=(19947) is not present in table "device".

But the record is there, it was inserted into net.computer so it's
selectable from net.device and from net.computer.

select id,parent_id,name,ip_address from net.device where id = 19947;
id | parent_id | name | ip_address
-------+-----------+-----------------+--------------------
19947 | 1649 | pc-lit-customer | 213.213.213.213/30

select id,parent_id,name,ip_address from net.computer where id = 19947;
id | parent_id | name | ip_address
-------+-----------+-----------------+--------------------
19947 | 1649 | pc-lit-digistyl | 213.250.201.222/30

There are other records in the net.computer which are referenced in other
records as the parent_id.

It really puzzles me.

If you want I can send you full definition of the net.device and the
net.computer including indices, triggers etc.

I have inserted 1795 records to net.device

select count(*) from only net.device;
count
-------
1795

and 5105 records to net.computer

select count(*) from only net.computer;
count
-------
5105

That's 6900 records in total

select count(*) from net.device;
count
-------
6900

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Dave Page 2010-06-09 08:29:09 Re: BUG #5475: Problem during Instalation
Previous Message Craig Ringer 2010-06-09 07:56:23 Re: BUG #5475: Problem during Instalation