Received: from maia.hub.org (maia-4.hub.org [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id C3997633503 for ; Tue, 4 May 2010 10:55:24 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 63925-07 for ; Tue, 4 May 2010 13:55:16 +0000 (UTC) X-Greylist: delayed 00:05:26.999893 by SQLgrey-1.7.6 Received: from lion02.hosting.nl (lion02.hosting.nl [62.129.139.91]) by mail.postgresql.org (Postfix) with ESMTP id DAD26633488 for ; Tue, 4 May 2010 10:55:16 -0300 (ADT) Received: from lionhead.nl (static.kpn.net [83.232.157.250] (may be forged)) by lion02.hosting.nl (8.13.8/8.13.8) with ESMTP id o44DnkQP016751 for ; Tue, 4 May 2010 15:49:46 +0200 Received: from lionhead2.lionhead.nl (localhost.localdomain [127.0.0.1]) by lionhead.nl (8.13.8/8.13.8) with ESMTP id o44Dnje0013345 for ; Tue, 4 May 2010 15:49:45 +0200 Date: Tue, 4 May 2010 15:49:45 +0200 From: "David Weilers" To: pgsql-sql Message-ID: Subject: Foreign key constraint referencing a parent table x-scalix-Hops: 1 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-5 required=5 tests=BAYES_50=0.8 X-Spam-Level: X-Archive-Number: 201005/13 X-Sequence-Number: 34061 Hi, I have a problem when inserting rows into my table tblfactuurpost that=20 references a table tblfactuur which is a parent to tblclientfactuur. =20 The actual row is inserted into tblfactuur. The problem is that i cannot insert the row into tblfactuurpost (which=20 references the parent table tblfactuur) because PSQL complains the=20 referencing ID (2) is missing while it is actually *not* missing at all. Thanks to anyone who can shed some light ... I have the following table set-up: CREATE TABLE tblfactuur ( id serial PRIMARY KEY, number int NOT NULL, year int NOT NULL CHECK (year>=3D1900 AND year<=3D2999), vanaf date NOT NULL, tot date NOT NULL CHECK (tot > vanaf), total int -- totaalbedrag in centen ); CREATE TABLE tblclientfactuur ( client int NOT NULL REFERENCES tblclient (id) ON DELETE RESTRICT , PRIMARY KEY (id) ) INHERITS (tblfactuur); CREATE TABLE tblfactuurpost ( id serial PRIMARY KEY, factuur int NOT NULL REFERENCES tblfactuur (id) ON DELETE CASCADE=20 DEFERRABLE, omschrijving varchar(128), btw smallint DEFAULT 19, -- standaard 19% btw aantal decimal(8,1) NOT NULL CHECK (aantal >=3D 0), -- aantal perstuk int NOT NULL CHECK (perstuk >=3D 0), -- bedrag per stuk in=20 centen amount int NOT NULL CHECK (amount >=3D 0), -- totaal bedrag in centen position smallint CHECK (position >=3D 0) ); This is the data in tblfactuur: (db)=3D> select * from tblfactuur; id | number | year | vanaf | tot | total ----+--------+------+------------+------------+-------- 2 | 1 | 2010 | 2010-03-01 | 2010-04-01 | 397800 (1 row) I try to insert:=20 insert into tblfactuurpost (factuur, omschrijving, btw, aantal, perstuk,=20 amount, position) select ?, ?, ?, ?, ?, ?, count(*) from tblfactuurpost where factuur=20 =3D ?; parameters: (2, Gespecialiseerde 24 uur zorg ma. t/m vr., 19, 156, 1425,=20 397800, 2) Regards, David