Re: child table doesn't inherit PRIMARY KEY?

From: Louis-David Mitterrand <cunctator(at)apartia(dot)ch>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: child table doesn't inherit PRIMARY KEY?
Date: 2000-06-03 15:51:56
Message-ID: 20000603175156.A4073@styx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-general pgsql-hackers

On Sat, Jun 03, 2000 at 05:22:56PM +0200, Louis-David Mitterrand wrote:
> When creating a child (through CREATE TABLE ... INHERIT (parent)) it
> seems the child gets all of the parent's contraints _except_ its PRIMARY
> KEY. Is this normal? Should I add a PRIMARY KEY(id) statement each time
> I create an inherited table?

Following up to my previous message, I found that one can't explicitely
add a PRIMARY KEY on child table referencing a field on the parent
table, for instance:

CREATE TABLE auction (
id SERIAL PRIMARY KEY,
title text,
... etc...
);

then

CREATE TABLE auction_dvd (
zone int4,
PRIMARY KEY("id")
) inherits("auction");

doesn't work:
ERROR: CREATE TABLE: column 'id' named in key does not exist

But the aution_dvd table doesn't inherit the auction table's PRIMARY
KEY, so I can insert duplicates.

Solutions:

1) don't use PRIMARY KEY, use UNIQUE NOT NULL (which will be inherited?)
but the I lose the index,

2) use the OID field, but it's deprecated by PG developers?

What would be the best solution?

TIA

--
Louis-David Mitterrand - ldm(at)apartia(dot)org - http://www.apartia.fr

Veni, Vidi, VISA.

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Peter Eisentraut 2000-06-03 22:44:26 Re: Documentation of configuration settings
Previous Message Louis-David Mitterrand 2000-06-03 15:22:56 child table doesn't inherit PRIMARY KEY?

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-06-03 16:36:58 Re: Re: Industrial-Strength Logging
Previous Message Kari Lempiainen 2000-06-03 15:51:25 Any monitor programs?

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2000-06-03 16:36:58 Re: Re: Industrial-Strength Logging
Previous Message Louis-David Mitterrand 2000-06-03 15:22:56 child table doesn't inherit PRIMARY KEY?