pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christof Glaser <gcg@gl.aser.de>
To: Kevin Way <kevin.way@overtone.org>
To: pgsql-sql@postgresql.org
Subject: Re: table inheritance and foreign key troubles
Date: Tue, 11 Sep 2001 12:49:13 +0200
Message-ID: <20010911104915.9400813098@pinguin.gl.aser.de> (raw)
In-Reply-To: <20010911091250.B8DD213061@pinguin.gl.aser.de>
References: <20010911080452.A76783@bean.overtone.org>
	<20010911091250.B8DD213061@pinguin.gl.aser.de>

On Tuesday, 11. September 2001 11:12, I wrote before I thought:
> 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,

Sorry, I missed that line:
> >     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.

PG cannot inherit primary keys or unique constraints, I recall now. So  
you need to ensure uniqueness for users.node_id:
CREATE TABLE users (
  node_id   INT4 UNIQUE,
  ....
) INHERITS (node );

The constraints of users.node_id and node.node_id get merged magically.
This should work now on 7.1.3. I did test it this time.

Best regards,
Christof
-- 
	  gl.aser . software engineering . internet service
       http://gl.aser.de/ . Planckstraße 7 . D-39104 Magdeburg



view thread (5+ messages)  latest in thread

Message-ID: <20010911104915.9400813098@pinguin.gl.aser.de>
Permalink:  ../20010911104915.9400813098@pinguin.gl.aser.de/
Also on:    postgresql.org/message-id/20010911104915.9400813098@pinguin.gl.aser.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gcg@gl.aser.de, kevin.way@overtone.org
  Subject: Re: table inheritance and foreign key troubles
  In-Reply-To: <20010911104915.9400813098@pinguin.gl.aser.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox