Re: postgres transaction isolation when rollback

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Tomer Levinboim" <levinboim(dot)tomer(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: postgres transaction isolation when rollback
Date: 2006-07-03 03:27:13
Message-ID: 22534.1151897233@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

"Tomer Levinboim" <levinboim(dot)tomer(at)gmail(dot)com> writes:
> Suppose now that the order is like so
> transaction 1: UPDATE accounts SET balance = balance + 100.00 WHERE acctnum
> = 12345;
> transaction 2: UPDATE accounts SET balance = balance + 200.00 WHERE acctnum
> = 12345;
> transaction 1: transaction failure
> transaction 2: UPDATE accounts SET balance = balance - 200.00 WHERE acctnum
> = 7534;

> Would the balance of account 12345 increase by 200 or 300 ?

200. Transaction 2 will block at its first UPDATE waiting to see if
transaction 1 commits or not, and will then use the appropriate version
of the row as the starting point for its update.

(I'm assuming you're speaking of READ COMMITTED rules here --- if T2
is SERIALIZABLE then the answer is different.)

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Guido Barosio 2006-07-03 04:20:39 Re: Password Help?
Previous Message Richard Broersma Jr 2006-07-03 02:09:47 Re: Insert more then one row