Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f75M2H698736 for ; Sun, 5 Aug 2001 18:02:17 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.4/8.11.4) id f75Lp2v77530 for pgsql-sql@postgresql.org; Sun, 5 Aug 2001 17:51:02 -0400 (EDT) (envelope-from news) From: Allan Engelhardt X-Newsgroups: comp.databases.postgresql.sql Subject: Inheritance is completely broken [was: Re: Creating foreign key constraint to child table?] Date: Sun, 05 Aug 2001 22:50:37 +0100 Organization: http://cybaea.com/ Message-ID: <3B6DBFAD.CF65A1C5@cybaea.com> References: <3B6DA4C4.CEC3B8F2@cybaea.com> X-NNTP-Posting-Host: engelhardt.demon.co.uk:193.237.12.86 X-Complaints-To: abuse@demon.net X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.7 i686) X-Accept-Language: en MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 72 To: pgsql-sql@postgresql.org X-Archive-Number: 200108/48 X-Sequence-Number: 4269 Dimitri pointed out (the post does not seem to have appered yet) that you can also do: test=# create table foo(id integer primary key); NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'foo_pkey' for table 'foo' CREATE test=# create table bar () inherits (foo); CREATE test=# insert into foo values (1); INSERT 12734236 1 test=# insert into foo values (1); ERROR: Cannot insert a duplicate key into unique index foo_pkey test=# insert into bar values (1); INSERT 12734238 1 test=# select * from foo; id ---- 1 1 (2 rows) So inheritance does seem to be completely broken. There is also an entry in the TODO list Allow inherited tables to inherit index, UNIQUE constraint, and primary key, foreign key [inheritance] which seems to be related. It doesn't have a dash, so I guess I won't hold my breath.... Now I'm sad. Allan. Allan Engelhardt wrote: > Stephan Szabo wrote: > > > On Sun, 5 Aug 2001, Allan Engelhardt wrote: > > [see new example below] > > > Not that this is related to what you asked about precisely (I saw the > > response you made), but the query above also doesn't do what you think > > it does right now. It currently makes a reference to only foo, not > > any subchildren of foo. > > Oh, man! You are right, but this sux big time: there should not be an asymmetry between a FOREIGN KEY constraint and the SELECT statement. Now that the default is SQL_INHERITANCE ON, it should be the default for the constraint as well, IMHO. > > 1. Am I the only one who thinks this is a bug? > > 2. How would I get the behaviour I expect? Write my own trigger? :-P > > --- Allan. > > test=# create table foo (id integer primary key); > test=# create table bar () inherits (foo); > test=# create table baz (bar integer, > constraint fk_bar foreign key (bar) references foo(id)); > test=# insert into foo values (1); > test=# insert into bar values (2); > test=# insert into baz values (2); > ERROR: fk_bar referential integrity violation - key referenced from baz not found in foo > test=# select * from foo where id = 2; > id > ---- > 2 > (1 row) > > test=#