Last active
December 26, 2015 04:48
-
-
Save ppadron/7095522 to your computer and use it in GitHub Desktop.
"A serious limitation of the inheritance feature is that indexes (including unique constraints) and foreign key constraints only apply to single tables, not to their inheritance children. This is true on both the referencing and referenced sides of a foreign key constraint." http://www.postgresql.org/docs/9.3/static/ddl-inherit.html#DDL-INHERIT-…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE people ( | |
id serial primary key, | |
name text | |
); | |
CREATE TABLE scientists ( | |
university text | |
) INHERITS (people); | |
CREATE TABLE chefs ( | |
hat_size text | |
) INHERITS (people); | |
CREATE TABLE people_i_like ( | |
person_id integer references people(id), | |
reason text | |
); | |
insert into scientists values (default, 'Alice', 'MIT'); | |
insert into chefs values (default, 'Bob', 'medium'); | |
insert into people_i_like values (1, 'taught me math'); | |
--ERROR: insert or update on table "people_i_like" violates foreign key constraint "people_i_like_people_id_fkey" | |
--DETAIL: Key (person_id)=(1) is not present in table "people". |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment