Re: PRIMARY KEY and INHERITANCE

From: Ferruccio Zamuner <nonsolosoft(at)diff(dot)org>
To: hherb(at)malleenet(dot)net(dot)au
Cc: nonsolosoft(at)diff(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PRIMARY KEY and INHERITANCE
Date: 2001-01-02 00:34:55
Message-ID: 200101020034.f020Ytm14118@tnt.diff.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

From: Horst Herb <hherb(at)malleenet(dot)net(dot)au>
Date: Mon, 1 Jan 2001 10:09:52 +1100

>> create table a (
>> id serial primary key,
>> something text
>> );
>>
>> create table b (
>> morething text
>> ) inherits (a);
>>
>> create table c (
>> trouble int references b;
>> );

>> NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY
>> check(s) ERROR: PRIMARY KEY for referenced table "b" not found
>
>
>> How is possible to resolve this bug?
>> How is possible to talk about a ORDBMS with this kind of error?

> It is not a bug, I would call it a missing feature. I had the same problem,
> and somebody from this list helped me with a private email. I think this
> should be included in the FAQ and general documentation.
> What happens is that the attribute "id" is inherited, but the index on "id"
> is not. The workaround is:

> create unique index table_b_id on b(id);

> Then the index exists, and the foreign key can be referenced.

Thank you Horst,

I was very happy for this workaround: it could make me able to use classes
during the design and it could give me a power approach, but now:

\di
List of relations
Name | Type | Owner
---------------------------+-------+-------
a_pkey | index | fer
table_b_id | index | fer

# create table c (test int references b);
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
ERROR: PRIMARY KEY for referenced table "b" not found

I've also tried to build b_pkey unique index:
b_pkey | index | fer

The trouble still persists.

May someone give me another workaround for PostgreSQL 7.0.3?

Thank you in advance, \fer

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Larry Rosenman 2001-01-02 02:04:56 Re: pg_dumpall (7.1beta1, current CVS)
Previous Message Lawrence E. Rosenman 2001-01-01 19:51:56 RE: Current Sources/UW7.1.1