Re: INSERT/UPDATEs cycles and lack of phantom locking

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Florian Weimer <fweimer(at)bfk(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: INSERT/UPDATEs cycles and lack of phantom locking
Date: 2006-07-19 14:26:18
Message-ID: 25634.1153319178@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Florian Weimer <fweimer(at)bfk(dot)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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Erik Jones 2006-07-19 14:29:18 Re: Table Join (Maybe?)
Previous Message Merlin Moncure 2006-07-19 14:17:03 Re: [GENERAL] is there any dataware housing tools for postgresql