Re: Error on reference to inherited primary key

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: rpijlman(at)spamcop(dot)net
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Error on reference to inherited primary key
Date: 2001-04-14 18:50:09
Message-ID: Pine.BSF.4.21.0104141147150.65159-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 13 Apr 2001 rpijlman(at)spamcop(dot)net wrote:

> Creating tables this way:
>
> A has a primary key
> B inherits A
> C references B
>
> results in an error message on the CREATE TABLE for C (ERROR: PRIMARY KEY for referenced table "b" not found).
>
> To reproduce:
>
> create table A
> (
> id integer primary key
> );
>
> create table B
> (
> dummy integer
> ) inherits (A);
>
> create table C
> (
> ref integer references B
> );
>
> psql:repro.sql:14: ERROR: PRIMARY KEY for referenced table "b" not found
>
> AFAIK the SQL code is correct. B should inherit the primary key from A, so C should be able to reference B.

Primary keys/Unique constraints do not currently inherit (they should, but
there are some questions about how they should). If you want id to have
the properties of a primary key on B, you need to make a unique constraint
on B, I believe the NOT NULL is already inherited.

> The workaround appears to be explicitly naming the primary key column:
> create table C
> (
> ref integer references B(id)
> );

This will not work for 7.1 since it checks for unique constraints (see
above)

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message pgsql-bugs 2001-04-14 19:35:29 can't compile JDBC1
Previous Message Dennis Fleurbaaij 2001-04-14 18:31:38 me bad :)