Re: INSERT/UPDATEs cycles and lack of phantom locking
| От | Tom Lane |
|---|---|
| Тема | Re: INSERT/UPDATEs cycles and lack of phantom locking |
| Дата | |
| Msg-id | 25634.1153319178@sss.pgh.pa.us обсуждение |
| Ответ на | INSERT/UPDATEs cycles and lack of phantom locking (Florian Weimer <fweimer@bfk.de>) |
| Ответы |
Re: INSERT/UPDATEs cycles and lack of phantom locking
|
| Список | 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 по дате отправления: