pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Florian Weimer <fweimer@bfk.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: INSERT/UPDATEs cycles and lack of phantom locking
Date: Wed, 19 Jul 2006 10:26:18 -0400
Message-ID: <25634.1153319178@sss.pgh.pa.us> (raw)
In-Reply-To: <82zmf60zf4.fsf@mid.bfk.de>
References: <82zmf60zf4.fsf@mid.bfk.de>

Florian Weimer <fweimer@bfk.de> 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



view thread (4+ messages)  latest in thread

Message-ID: <25634.1153319178@sss.pgh.pa.us>
Permalink:  ../25634.1153319178@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25634.1153319178@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fweimer@bfk.de
  Subject: Re: INSERT/UPDATEs cycles and lack of phantom locking
  In-Reply-To: <25634.1153319178@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox