X-Original-To: pgsql-admin@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 456A44762D7 for ; Mon, 31 Mar 2003 10:41:40 -0500 (EST) Received: from bragi.msys.ch (bragi.msys.ch [157.161.101.6]) by postgresql.org (Postfix) with ESMTP id 7BB61476543 for ; Mon, 31 Mar 2003 05:06:25 -0500 (EST) Received: from msys.ch (idun [157.161.101.130]) by bragi.msys.ch (8.12.3/8.12.3/SuSE Linux 0.6) with ESMTP id h2VA6Qmk013164 for ; Mon, 31 Mar 2003 12:06:26 +0200 Message-ID: <3E881322.7050403@msys.ch> Date: Mon, 31 Mar 2003 12:06:26 +0200 From: Beatrice Yueksel User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-admin@postgresql.org Subject: question regarding REFERENCES and INHERITS Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-12.3 required=5.0 tests=BAYES_01,UPPERCASE_25_50,USER_AGENT_MOZILLA_UA autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200303/495 X-Sequence-Number: 8135 Hi, I made some test with REFERENCES and INHERITS. I know from the mailing list that : "Referential integrity only applies to the named table and not any child tables..." I have 3 tables: art, schiff_admin (for administration with rules, view, etc...) schiff (inherits schiff_admin) There is one reference from schiff_admin to art. The reference doesn't work in schiff. If I add a constraint: ALTER TABLE schiff_admin ADD CONSTRAINT schiff_admin_fk_art FOREIGN KEY(art) REFERENCES schiff_art (art) ON DELETE NO ACTION ; the reference works also in schiff. Why the reference is inherited after the "alter table" and not before? Thank you in advance, Beatrice ____________________ First step. ____________________ Create sequence schiff_id_seq; Create table schiff_art ( art VARCHAR(4) PRIMARY KEY NOT NULL, bezeichnung VARCHAR(50) NOT NULL ); Create table schiff_admin ( schiff_id INTEGER DEFAULT nextval('schiff_id_seq') PRIMARY KEY NOT NULL, art VARCHAR(4) REFERENCES schiff_art, schiffsname VARCHAR(255) NOT NULL ) ; Create table schiff () INHERITS (schiff_admin); \d schiff_admin; Table "public.schiff_admin" Column | Type | Modifiers -------------+------------------------+------------------------------------------------- schiff_id | integer | not null default nextval('schiff_id_seq'::text) art | character varying(4) | schiffsname | character varying(255) | not null Indexes: schiff_admin_pkey primary key btree (schiff_id) Foreign Key constraints: $1 FOREIGN KEY (art) REFERENCES schiff_art(art) ON UPDATE NO ACTION ON DELETE NO ACTION \d schiff Table "public.schiff" Column | Type | Modifiers -------------+------------------------+------------------------------------------------- schiff_id | integer | not null default nextval('schiff_id_seq'::text) art | character varying(4) | schiffsname | character varying(255) | not null ____________________ Second step. ____________________ ALTER TABLE schiff_admin ADD CONSTRAINT schiff_admin_fk_art FOREIGN KEY(art) REFERENCES schiff_art (art) ON DELETE NO ACTION ; \d schiff_admin; Table "public.schiff_admin" Column | Type | Modifiers -------------+------------------------+------------------------------------------------- schiff_id | integer | not null default nextval('schiff_id_seq'::text) art | character varying(4) | schiffsname | character varying(255) | not null Indexes: schiff_admin_pkey primary key btree (schiff_id) Foreign Key constraints: $1 FOREIGN KEY (art) REFERENCES schiff_art(art) ON UPDATE NO ACTION ON DELETE NO ACTION, schiff_admin_fk_art FOREIGN KEY (art) REFERENCES schiff_art(art) ON UPDATE NO ACTION ON DELETE NO ACTION \d schiff; Table "public.schiff" Column | Type | Modifiers -------------+------------------------+------------------------------------------------- schiff_id | integer | not null default nextval('schiff_id_seq'::text) art | character varying(4) | schiffsname | character varying(255) | not null Foreign Key constraints: schiff_admin_fk_art FOREIGN KEY (art) REFERENCES schiff_art(art) ON UPDATE NO ACTION ON DELETE NO ACTION