X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4EEA7D1B4F6 for ; Thu, 18 Sep 2003 05:33:26 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 93202-03 for ; Thu, 18 Sep 2003 02:33:16 -0300 (ADT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 886C9D1B507 for ; Thu, 18 Sep 2003 02:33:15 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 8702635352; Wed, 17 Sep 2003 22:33:15 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 8583235351; Wed, 17 Sep 2003 22:33:15 -0700 (PDT) Date: Wed, 17 Sep 2003 22:33:15 -0700 (PDT) From: Stephan Szabo To: tom baker Cc: pgsql-sql@postgresql.org Subject: Re: transaction locking In-Reply-To: <200309172207.09134.postgres@atoka-software.com> Message-ID: <20030917223104.D58881@megazone.bigpanda.com> References: <200309172207.09134.postgres@atoka-software.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/173 X-Sequence-Number: 15151 On Wed, 17 Sep 2003, tom baker wrote: > i am (probably) shooting myself in the foot, but here goes the question. > > inside of a begin transaction/commit block, i am attempting to insert a record > into a parts table, and then insert a record that references the part into an > application table. and the transaction fails with this error message: > > ERROR: app_part_ins_trig referential integrity violation - key referenced from > application not found in parts > > i understand that since the record was inserted into the parts table *after* > the BEGIN TRANSACTION statement, the insert into the application table cannot > see that a record exists until a commit. Assuming that they are both in the same transaction, the second insert should be able to see the results of the first insert, can you send an example sequence of inserts as well? (Also see the note below) > and the constraint that is causing problems is: > CREATE CONSTRAINT TRIGGER app_part_ins_trig AFTER INSERT OR UPDATE ON > application FROM parts NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW > EXECUTE PROCEDURE "RI_FKey_check_ins" ('app_part_ins_trig', 'application', > 'parts', 'UNSPECIFIED', 'make', 'make', 'amc_part_no', 'amc_part_no'); > > $sql = "SET CONSTRAINTS ALL DEFERRED" ; I'm not sure if you know, but this is not going to deferr the constraint above because it was created with NOT DEFERRABLE.