Re: Inherit a primary key?

From: missive(at)frontiernet(dot)net (Lee Harr)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Inherit a primary key?
Date: 2001-07-25 23:04:34
Message-ID: 9jnja1$3hl8$3@node21.cwnet.roc.gblx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 26 Jul 2001 08:04:58 +1000, Paul Gear <paulgear(at)bigfoot(dot)com> wrote:
> Hi All,
>
> Can anyone tell me whether i am doing something wrong or if this is
> simply not supported at the moment?
>
> What i would like to do is have a generic object as the root of my
> table inheritance hierarchy, thus:
>
> create table object (
> id serial primary key,
> label text not null,
> notes text
> );
>
> And then inherit my actual entities from object, like this:
>
> create table bar (
> name text,
> version text
> ) inherits ( object );
>
> Then i would like to refer to the inherited table, like this:
>
> create table foo (
> name text,
> barid integer references bar,
> );
>
> However, when i try to create foo, i get this:
>
> NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN
> KEY check(s)
> ERROR: PRIMARY KEY for referenced table "bar" not found
>
> What seems to have happened is that all the fields of object were
> inherited by bar, but not the primary key. So there is no primary key
> for foo to reference, and the references clause fails.
>
> What is the problem? Is inheritance of primary keys not supported, or
> do i need to do something else?
>
> I'm using version 7.0.3 on Red Hat 7.1.
>

From the ToDo list:

Allow inherited tables to inerit index, UNIQUE contraint, and
primary key, foreign key.

There is also a page in ToDo detail about inheritance.

This one bit me before too. It seems like it would be a Good Thing.
Just waiting for someone to take on the challenge :)

Browse pgsql-general by date

  From Date Subject
Next Message Nathan Myers 2001-07-25 23:31:31 Re: Bad timestamp external representation
Previous Message Lee Harr 2001-07-25 22:54:57 Re: Compile problem on fBSD 4.3