Re: BUG #5188: Inheritance: bug or feature?

Lists: pgsql-bugs
From: "Peter Dobos" <dvc1201(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #5188: Inheritance: bug or feature?
Date: 2009-11-15 12:15:45
Message-ID: 200911151215.nAFCFjFL029044@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 5188
Logged by: Peter Dobos
Email address: dvc1201(at)gmail(dot)com
PostgreSQL version: 8.3.8
Operating system: Win XP
Description: Inheritance: bug or feature?
Details:

Hi,

I'm not sure that inherited table records are 'real' records in the ancestor
table.

Table definitions:
CREATE TABLE table1
(
tbl1_id integer NOT NULL,
CONSTRAINT pk_table1 PRIMARY KEY (tbl1_id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE table1 OWNER TO postgres;
GRANT ALL ON TABLE table1 TO postgres;
GRANT ALL ON TABLE table1 TO public;
-- Table: table1x

-- DROP TABLE table1x;

CREATE TABLE table1x
(
-- Inherited from table table1x: tbl1_id integer NOT NULL,
CONSTRAINT pk_table1x PRIMARY KEY (tbl1_id)
)
INHERITS (table1)
WITH (
OIDS=FALSE
);
ALTER TABLE table1x OWNER TO postgres;
GRANT ALL ON TABLE table1x TO postgres;
GRANT ALL ON TABLE table1x TO public;
-- Table: table2

-- DROP TABLE table2;

CREATE TABLE table2
(
tbl1_id integer,
CONSTRAINT fk_table1_of_table2 FOREIGN KEY (tbl1_id)
REFERENCES table1 (tbl1_id) MATCH SIMPLE
ON UPDATE RESTRICT ON DELETE RESTRICT
)
WITH (
OIDS=TRUE
);
ALTER TABLE table2 OWNER TO postgres;
GRANT ALL ON TABLE table2 TO postgres;
GRANT ALL ON TABLE table2 TO public;

insert into table1x (tbl1_id) values (1);
select * from table1;
You can see a record in table1 where tbl1_id=1

insert into table2 (tbl1_id) values (1);
********** Error **********

ERROR: insert or update on table "table2" violates foreign key constraint
"fk_table1_of_table2"
SQL state: 23503
Detail: Key (tbl1_id)=(1) is not present in table "table1".

I can't use a table1x record as a table1 record.

Best regards,
Peter Dobos


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Peter Dobos" <dvc1201(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5188: Inheritance: bug or feature?
Date: 2009-11-15 16:02:10
Message-ID: 19635.1258300930@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Peter Dobos" <dvc1201(at)gmail(dot)com> writes:
> I'm not sure that inherited table records are 'real' records in the ancestor
> table.

They're not. In particular see
http://www.postgresql.org/docs/8.3/static/ddl-inherit.html#DDL-INHERIT-CAVEATS

regards, tom lane