Re: INSERT/UPDATEs cycles and lack of phantom locking - Mailing list pgsql-sql

From Tom Lane
Subject Re: INSERT/UPDATEs cycles and lack of phantom locking
Date
Msg-id 25634.1153319178@sss.pgh.pa.us
Whole thread Raw
In response to INSERT/UPDATEs cycles and lack of phantom locking  (Florian Weimer <fweimer@bfk.de>)
Responses Re: INSERT/UPDATEs cycles and lack of phantom locking  (Florian Weimer <fweimer@bfk.de>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Chris Browne
Date:
Subject: Re: Sequences, values still increased
Next
From: Erik Jones
Date:
Subject: Re: Table Join (Maybe?)