X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 4055C9FA4A7 for ; Wed, 19 Jul 2006 11:26:25 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 72166-06 for ; Wed, 19 Jul 2006 14:26:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id F16D29FA47F for ; Wed, 19 Jul 2006 11:26:21 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k6JEQIlx025635; Wed, 19 Jul 2006 10:26:18 -0400 (EDT) To: Florian Weimer cc: pgsql-sql@postgresql.org Subject: Re: INSERT/UPDATEs cycles and lack of phantom locking In-reply-to: <82zmf60zf4.fsf@mid.bfk.de> References: <82zmf60zf4.fsf@mid.bfk.de> Comments: In-reply-to Florian Weimer message dated "Wed, 19 Jul 2006 10:30:39 +0200" Date: Wed, 19 Jul 2006 10:26:18 -0400 Message-ID: <25634.1153319178@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/248 X-Sequence-Number: 25822 Florian Weimer writes: > BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED; -- SERIALIZABLE > ... > -- SAVEPOINT tmp_created; -- (see below) > CREATE TEMPORARY TABLE tmp2 AS SELECT tmp.key, new_val, real.val AS old_val > FROM tmp LEFT OUTER JOIN real ON tmp.key = real.key; > UPDATE real SET val = new_val + old_val FROM tmp2 > WHERE old_val IS NOT NULL AND tmp2.key = real.key; > INSERT INTO real SELECT key, new_val FROM tmp2 WHERE old_val IS NULL; > If this is run concurrently, the INSERT may fail. In this case, I > rerun the transaction. Actually, I want to rollback to the > tmp_created checkpoint, but I don't think this will pick up the new > rows in the "real" table, and the INSERT will fail again. Why do you think that? If you're running in READ COMMITTED mode then each statement takes a new snapshot. regards, tom lane