Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E7EA1633C58 for ; Mon, 20 Jul 2009 10:33:14 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 33815-06 for ; Mon, 20 Jul 2009 10:32:55 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from milkno.com (pfeiffer02.nmmn.net [217.114.78.33]) by mail.postgresql.org (Postfix) with ESMTP id 123F2633BAF for ; Mon, 20 Jul 2009 10:33:04 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by milkno.com (Postfix) with ESMTP id AD05015CC08D; Mon, 20 Jul 2009 15:32:54 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at milkno.com Received: from milkno.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id gXDQhoMs2rvp; Mon, 20 Jul 2009 15:32:54 +0200 (CEST) Received: from [192.168.97.30] (automatix.transfer.langbehn.hh.nmmn.net [217.114.64.90]) by milkno.com (Postfix) with ESMTPA id CF74A15CC08C; Mon, 20 Jul 2009 15:32:53 +0200 (CEST) Message-ID: <4A64720B.1060904@netzmeister-st-pauli.de> Date: Mon, 20 Jul 2009 15:32:59 +0200 From: Andreas Wenk User-Agent: Thunderbird 2.0.0.22 (X11/20090608) MIME-Version: 1.0 To: Gianvito Pio , pgsql-sql@postgresql.org Subject: Re: Table inheritance problem References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.003 tagged_above=0 required=5 tests=AWL=0.003 X-Spam-Level: X-Archive-Number: 200907/85 X-Sequence-Number: 32826 Gianvito Pio schrieb: > Hello, > I have 3 tables: persons, operators and persons_position. > > This is a semplified examples of their structures: > > CREATE TABLE persons > (id varchar NOT NULL, > CONSTRAINT "PK_Persons" PRIMARY KEY(id)); > > > CREATE TABLE operators > (id varchar NOT NULL, > CONSTRAINT "PK_Operators" PRIMARY KEY(id)) > INHERITS(persons); > > CREATE TABLE persons_position > (id bigserial NOT NULL, > person varchar NOT NULL); > > and then there is a FOREIGN KEY CONSTRAINT from persons_position.person > TO persons.id. > > If I insert a tuple in operators...it results also in persons, but when > I insert a tuple in persons_position, it says me I have violated the > foreing key constraints. So it appears that the tuple really ISN'T in > the persons table and the foreing key check fails. > > How could I solve it, keeping the inheritance there? > Thanks Hi, sure it does throw that error. Your foreign key constraint is wrong. The check will look like this: test=# insert into persons_position values(2,'andy'); ERROR: insert or update on table "persons_position" violates foreign key constraint "persons_position_persons_fkey" DETAIL: Key (person)=(andy) is not present in table "persons". You could solve it by altering the table persons: test=# alter table persons add column person varchar(255); ALTER TABLE test=# insert into persons_position values(2,'andy'); INSERT 0 1 Or change the foreign key constraint in persons_position to id (be careful - the datatypes are different) Cheers Andy