All pastes #277604 Raw Edit

phoemix

public sql v1 · immutable
·published 2006-12-13 12:02 UTC
rendered paste body
CREATE TABLE "ancestor" (        "id"            integer         NOT NULL,        "name"          varchar(32)     NOT NULL,        PRIMARY KEY     ("id"));CREATE TABLE "child" (        "attr1"         integer         NOT NULL) INHERITS ("ancestor");CREATE TABLE "reference" (        "id"            integer         NOT NULL,        "ancid"         integer         NOT NULL,        PRIMARY KEY     ("id"),        FOREIGN KEY     ("ancid")       REFERENCES      "ancestor"("id"));INSERT INTO "ancestor" (id,name) VALUES (1,'ancfoo');INSERT INTO "child" (id,name,attr1) VALUES (2,'childfoo', 2);INSERT INTO "reference" (id,ancid) VALUES (1,1);-- till here it's OKINSERT INTO "reference" (id,ancid) VALUES (2,2);-- here:-- ERROR:  insert or update on table "reference" violates foreign key constraint "reference_ancid_fkey"-- DETAIL:  Key (ancid)=(2) is not present in table "ancestor".