Received: from pinguin.gl.aser.de (pec-56-10.tnt3.b2.uunet.de [149.225.56.10]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8B98g765155 for ; Tue, 11 Sep 2001 05:08:42 -0400 (EDT) (envelope-from gcg@gl.aser.de) Received: by pinguin.gl.aser.de (Postfix, from userid 1000) id B8DD213061; Tue, 11 Sep 2001 11:12:50 +0200 (CEST) Content-Type: text/plain; charset="iso-8859-1" From: Christof Glaser Organization: gl.aser . software engineering . internet service To: Kevin Way , pgsql-sql@postgresql.org Subject: Re: table inheritance and foreign key troubles Date: Tue, 11 Sep 2001 11:12:49 +0200 X-Mailer: KMail [version 1.3.1] References: <20010911080452.A76783@bean.overtone.org> In-Reply-To: <20010911080452.A76783@bean.overtone.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <20010911091250.B8DD213061@pinguin.gl.aser.de> X-Archive-Number: 200109/51 X-Sequence-Number: 4697 On Tuesday, 11. September 2001 10:04, Kevin Way wrote: > I'm having a little trouble with some inherited tables and a foreign > key. Here's a simplified case, to show the trouble. > > CREATE TABLE node ( > node_id SERIAL NOT NULL, > name TEXT NOT NULL, > PRIMARY KEY (node_id) > ); > -- works just fine > > CREATE TABLE users ( > email TEXT NOT NULL > ) INHERITS (node); > -- so far so good.... > > CREATE TABLE item ( > reason TEXT NOT NULL, > author_id INT NOT NULL REFERENCES users (node_id) > ) INHERITS (node); > ERROR: UNIQUE constraint matching given keys for referenced table > "users" not found That means, there is no UNIQUE constraing on users.node_id ;-) Since users inherits that field from node, just make node.node_id unique, or even a primary key. > Does this operation just require differing syntax, because the > referenced field is inherited from another table, or is this not > possible? In previous versions of Postgres it was possible to reference non-unique fields. With 7.1.x this is, correctly, no longer possible. Inheritance doesn't have anything do to with it in your case, though. Hope that helps, Christof -- gl.aser . software engineering . internet service http://gl.aser.de/ . Planckstraße 7 . D-39104 Magdeburg