Answer the question
In order to leave comments, you need to log in
Postgres, foreign key to parent(in inheritance mean) table:impossible?
The situation is as follows: there is a common table for all types of documents:
create table document(<br/>
id bigserial,<br/>
title text,<br/>
prinary key(id)<br/>
);
create table purchase_request(<br/>
...<br/>
primary key()id<br/>
)<br/>
inherits(document)<br/>
create table document_items(<br/>
document_id bigint references document(id),<br/>
item_id bigint references items(id),<br/>
)
Answer the question
In order to leave comments, you need to log in
I'll say shcha for mysql but I think the reason is the same: When you insert a record, and there is a forenkey, then in fact one table is obtained leading, the other slave. That is, to insert a record into a slave table, there must already be a record with such a key in the master table (roughly speaking). Or, when creating a foreign key, remove the actions and allow zero as a value for the field. It's messy, of course, but somehow it works =)
It turned out that the answer to this question is in the instructions for Postgres. Literally: There is no good workaround for this case.
www.postgresql.org/docs/9.1/static/ddl-inherit.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question