Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 9DE989FB668 for ; Fri, 9 Mar 2007 08:05:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 61149-03 for ; Fri, 9 Mar 2007 08:05:47 -0400 (AST) X-Greylist: delayed 00:22:46.851369 by SQLgrey-1.7.4 Received: from eiger.itds.ch (eiger.itds.ch [217.150.247.100]) by postgresql.org (Postfix) with ESMTP id E66FC9FB5C0 for ; Fri, 9 Mar 2007 08:05:46 -0400 (AST) Received: from 205-209-221-213-pool.cable.fcom.ch ([213.221.209.205] helo=intra-mailex-01.kobelnet.intra) by eiger.itds.ch with esmtpsa (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.52) id 1HPdUw-0003E6-FL for pgsql-sql@postgresql.org; Fri, 09 Mar 2007 12:42:58 +0100 Received: from weisshorn.kobelnet.intra ([192.168.0.11]) by intra-mailex-01.kobelnet.intra with esmtp (Exim 4.50) id 1HPdUw-0000J7-Hk for pgsql-sql@postgresql.org; Fri, 09 Mar 2007 11:42:58 +0000 Received: from moritz by weisshorn.kobelnet.intra with local (Exim 4.63) (envelope-from ) id 1HPdV1-0004fr-I8 for pgsql-sql@postgresql.org; Fri, 09 Mar 2007 12:43:03 +0100 Date: Fri, 9 Mar 2007 12:43:03 +0100 From: Moritz Kobel To: pgsql-sql@postgresql.org Subject: Table inherit & foreign key problem Message-ID: <20070309114303.GC12129@alvier.kobelnet.intra> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Editor: Vim http://www.vim.org/ X-Location: Europe, Switzerland X-Operating-System: weisshorn.kobelnet.intra Linux 2.6.18-3-686 X-Display-Host: alvier.kobelnet.intra User-Agent: mutt-ng/devel-r804 (Debian) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.136 tagged_above=0 required=5 tests=BAYES_50, FORGED_RCVD_HELO, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200703/98 X-Sequence-Number: 27736 Hi all, i have problems with tables an foreign keys. i created the following tables: (i did not copy all the command, only the important (in my point of view) CREATE TABLE element ( id bigint NOT NULL, site_id bigint, type_id bigint NOT NULL, name character varying(512), description text, active boolean NOT NULL ); CREATE TABLE crmuser ( username character varying(32) NOT NULL, firstname character varying(64), lastname character varying(64) ) INHERITS (element); CREATE TABLE "comment" ( user_id bigint, created timestamp without time zone, content text, element_id bigint NOT NULL ) INHERITS (element); CREATE INDEX idx_comment_id ON "comment" USING btree (id); CREATE INDEX idx_comment_user_id ON "comment" USING btree (user_id); CREATE INDEX idx_comment_element_id ON "comment" USING btree (element_id); ALTER TABLE ONLY element ADD CONSTRAINT element_pkey PRIMARY KEY (id); ALTER TABLE ONLY crmuser ADD CONSTRAINT crmuser_pkey PRIMARY KEY (id); ALTER TABLE ONLY "comment" ADD CONSTRAINT comment_pkey PRIMARY KEY (id); ALTER TABLE ONLY "comment" ADD CONSTRAINT "$3" FOREIGN KEY (user_id) REFERENCES crmuser(id); ALTER TABLE ONLY "comment" ADD CONSTRAINT "$4" FOREIGN KEY (element_id) REFERENCES element(id); when i try to insert an comment with element_id = id of an user which is visible when i call "select * from element", i get an foreign key violation error: element_id=XY is not available in element. i would like to reference to the element table, because i have some tables which inherit from element and i would like to add comments to these elements. is this impossible or did i do a silly mistake? i did not find a solution unsing google. - Moritz -- Wissen ist das einzige Gut, das sich vermehrt, wenn man es teilt. -- http://www.lagerkochbuch.ch