Table Inheritance and foreign key problem.

From: "Kostas Maistrelis" <pinakas(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Table Inheritance and foreign key problem.
Date: 2006-07-23 11:59:53
Message-ID: 377c89a20607230459l79271c5fnc25e09dc9d62ab36@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I make 3 tables with this senario:
b (id) extends a (id)
and
c (id) references a (id)

i insert one record to table b (id = 1)
and then i try to insert a record in table C (id = 1)
but it is not possible, i get error
(look at the sql statements above)

NOTE
if the C (id) references the b (id) the insert in table C
is possible.

I try this to postgresql 8.1.2 and 8.1.4

above is the exact SQL STATMENTS:

============================================

DROP TABLE a;
DROP TABLE b;
DROP TABLE c;

CREATE TABLE a (id integer primary key);

CREATE TABLE b (id integer primary key) INHERITS (a);

CREATE TABLE c (id integer primary key references a(id));

insert into b values (1);

SELECT * from b;
id
----
1
(1 row)

SELECT * from a;
id
----
1
(1 row)

INSERT INTO c VALUES (1);
ERROR: insert or update on table "c" violates foreign key constraint
"c_id_fkey"
DETAIL: Key (id)=(1) is not present in table "a".

============================================

Thanks

Kostas Maistrelis.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2006-07-23 14:17:51 Re: Table Inheritance and foreign key problem.
Previous Message Michael Fuhr 2006-07-23 01:17:41 Re: join table with empty fields and default