[pgsql] inherits and foreign key problem - Mailing list pgsql-general

From Magicloud Magiclouds
Subject [pgsql] inherits and foreign key problem
Date
Msg-id 3bd412d40704231930q33582708s8b5eaa79a744d5a5@mail.gmail.com
Whole thread Raw
Responses Re: [pgsql] inherits and foreign key problem  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-general
Dear all,
    I have some tables like below, and now i have one record for each
in simple_texts, simple_directories and side_types. Now I want to
insert one record into sides (from simple_directory to simple_text
with side_type), but it report error: can not insert or update
"sides", against foreign key "sides_from_fkey". detail: key (from)=(2)
is not present in table "base_nodes".
    How does this happen? How to resolve?

Thanks.
---
CREATE TABLE base_nodes
(
  id bigserial NOT NULL UNIQUE
);
CREATE TABLE name_descriptions
(
  name varchar (256) NOT NULL PRIMARY KEY,
  description text NOT NULL,
  UNIQUE (id)
) INHERITS (base_nodes);
CREATE TABLE side_types
(
  UNIQUE (id),
  PRIMARY KEY (name)
) INHERITS (name_descriptions);
CREATE TABLE sides
(
  "from" int8 NOT NULL REFERENCES base_nodes (id) ON DELETE CASCADE,
  "to" int8 NOT NULL REFERENCES base_nodes (id) ON DELETE CASCADE,
  "type" int8 NOT NULL REFERENCES side_types (id) ON DELETE CASCADE,
  PRIMARY KEY ("from", "to", "type")
) INHERITS (base_nodes);
CREATE TABLE users
(
  "password" char (128) NOT NULL,
  UNIQUE (id),
  PRIMARY KEY (name)
) INHERITS (name_descriptions);
CREATE TABLE simple_texts
(
  context text NOT NULL,
  UNIQUE (id),
  PRIMARY KEY (name)
) INHERITS (name_descriptions);
CREATE TABLE simple_directories
(
  UNIQUE (id),
  PRIMARY KEY (name)
) INHERITS (name_descriptions);

pgsql-general by date:

Previous
From: Jorge Godoy
Date:
Subject: Re: where clause help
Next
From: Tom Lane
Date:
Subject: Re: PG service restart failure (start getting ahead of stop?)