Foreign keys referencing parent table fails on insert
От | postgresbugs |
---|---|
Тема | Foreign keys referencing parent table fails on insert |
Дата | |
Msg-id | 41AE2276.40107@grifent.com обсуждение исходный текст |
Ответы |
Re: Foreign keys referencing parent table fails on insert
|
Список | pgsql-bugs |
Foreign keys referencing parent table fails on insert if the key is in the table that inherits the parent table. I am using psql (PostgreSQL) 7.4.2. I have created a trivial case for an example. create table trivial1 (id numeric primary key, numval numeric); create table trivial2 (textval text)inherits (trivial1); insert into trivial2 values(1,1,'test1'); create table trivial3 (id numeric, subkey numeric,CONSTRAINT trivial3_c1 PRIMARY KEY (id, subkey),FOREIGN KEY (id) REFERENCES trivial1(id)); insert into trivial3 VALUES (1,0); ERROR: insert or update on table "trivial3" violates foreign key constraint "$1" DETAIL: Key (id)=(1) is not present in table "trivial1". select * from trivial1; id | numval ----+-------- 1 | 1 (1 row) While it is true in the strict sense that the key is not in table "trivial1", the key is in the table "trivial1" in the general sense since a select on the table does retrieve the key value. There is an additional problem in that the primary key is not enforced across the parent (inherited) and child (inheriting) tables. This really should not work but does. insert into trivial1 values (1,1); INSERT 640907 1 A subsequent select give the impression of a violated primary key. I realize this is not true in the strict sense but appears as a violation because of the inheritance. select * from trivial1; id | numval ----+-------- 1 | 1 1 | 1 (2 rows) Creating trivial2 using create table trivial2 (textVal text, primary key (id))inherits (trivial1); does not change the results. Am I missing something? Regards, John Griffiths
В списке pgsql-bugs по дате отправления: