Skip site navigation (1) Skip section navigation (2)

BUG #1514: Inheritance and Primary Keys

From: "Peter Newman" <pnewman(at)wanadoo(dot)nl>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1514: Inheritance and Primary Keys
Date: 2005-03-02 15:23:27
Message-ID: (view raw or whole thread)
Lists: pgsql-bugs
The following bug has been logged online:

Bug reference:      1514
Logged by:          Peter Newman
Email address:      pnewman(at)wanadoo(dot)nl
PostgreSQL version: 7.4.7
Operating system:   Fedora Core 3
Description:        Inheritance and Primary Keys


Just exploring the use of inheritance to so some design problems and found
some strange behaviour.  Not sure if this is a bug or feature?


create table cities (id serial primary key, name varchar(45));
create table capitals (state char(2)) inherits (cities);

insert into cities values (1, 'Paris');
insert into cities values (1, 'London');

The second one fails naturally however if you were to
insert into capitals values (1, 'Paris', 'FR');
insert into capitals values (1, 'London', 'UK');

This is fine.  And if 
create table capitals (state char(2), primary key (id)) inherits (cities);
create table non_capitals (state char(2), primary key (id)) inherits
insert into capitals values (1, 'Paris', 'FR');
insert into non_capitals values (1, 'London', 'UK');

is also okay.

If you were to insert data like this:
insert into capitals (name, state) values ('Paris', 'FR');
insert into non_capitals (name, state) values ('London', 'UK');

then the ids in cities would be 1 and 2 using the serial sequencing.  This
seems inconsistent at least.

So my point is (if it is not clear) that the primary key constraint is not
enforced through subclass tables.  Is this intentional?



pgsql-bugs by date

Next:From: Rick RomanDate: 2005-03-02 16:18:31
Subject: relation "pg_user" does not exist
Previous:From: Michael FuhrDate: 2005-03-02 08:38:05
Subject: Re: Errors using Postgres 7.4.6

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group