Re: table inheritance and foreign key troubles - Mailing list pgsql-sql

From Stephan Szabo
Subject Re: table inheritance and foreign key troubles
Date
Msg-id Pine.BSF.4.21.0109110349380.20489-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Re: table inheritance and foreign key troubles  (Christof Glaser <gcg@gl.aser.de>)
List pgsql-sql
(hopefully this doesn't double post... stupid mail system)

On Tue, 11 Sep 2001, Christof Glaser wrote:

> 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.

Actually node.node_id looks to be a pkey, but primary keys/unique don't
inherit, so users.node_id doesn't have the constraint.  You'll need
a primary key(node_id) on users as well (note that this won't actually
enforce that values are unique across both node and users just within
each table. See past discussions about inheritance and foreign keys...




pgsql-sql by date:

Previous
From: Christof Glaser
Date:
Subject: Re: table inheritance and foreign key troubles
Next
From: patrick.jacquot@anpe.fr
Date:
Subject: referencing oid impozsible ?