Re: [HACKERS] Re: PRIMARY KEY & INHERITANCE (fwd)

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Chris Bitmead <chrisb(at)nimrod(dot)itg(dot)telstra(dot)com(dot)au>
Cc: nonsolosoft(at)diff(dot)org, pgsql-general(at)hub(dot)org, "pgsql-hackers(at)postgreSQL(dot)org" <pgsql-hackers(at)postgreSQL(dot)org>
Subject: Re: [HACKERS] Re: PRIMARY KEY & INHERITANCE (fwd)
Date: 2000-07-19 05:25:26
Message-ID: Pine.BSF.4.10.10007182217280.64474-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Wed, 19 Jul 2000, Chris Bitmead wrote:

> Something on the TODO list is that indexes should be inherited by
> default. Unfortunately, right now they are not. I'm not sure what the
> interaction is here with the foreign key mechanism, so I'm CCing this to
> hackers to see if anyone there might comment.

If you don't specify a set of target columns for the reference, it goes to
the primary key of the table (if one exists). If one doesn't we error out
as shown below. You can make the reference by saying:
advert_id int4 not null references advert(id)
in the definition of table work.

Of course, in this case, I don't even see a primary key being defined on
either picture or advert, so it's not really the inheritance thing unless
he also made an index somewhere else (not using unique or primary key on
the table).

In 7.1, the ability to reference columns that are not constrained to be
unique will probably go away, but you can also make the index on
advert(id) to make it happy in that case.

> > CREATE TABLE picture (
> > id serial not null,
> > description text,
> > filename text);
> >
> > CREATE TABLE advert (
> > artist text,
> > customer text,
> > target text)
> > INHERITS (picture);
> >
> > CREATE TABLE work (
> > id serial not null,
> > advert_id int4 not null references advert,
> > value numeric(6,2) default 0);
> >
> > NOTICE: CREATE TABLE will create implicit sequence 'work_id_seq' for SERIAL
> > col
> > umn 'work.id'
> > NOTICE: CREATE TABLE/UNIQUE will create implicit index 'work_id_key' for
> > table
> > 'work'
> > NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
> > ERROR: PRIMARY KEY for referenced table "advert" not found

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Mittermayer 2000-07-19 05:33:58 tcl/tk interface on Digital Unix
Previous Message Chris Bitmead 2000-07-19 03:56:35 Re: PRIMARY KEY & INHERITANCE (fwd)

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Lockhart 2000-07-19 06:42:22 Docs organized as a "set"
Previous Message Tom Lane 2000-07-19 04:51:24 Re: MySQL comparison