From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | mwaples(at)waples(dot)net, pgsql-general(at)postgresql(dot)org |
Subject: | Re: concurrent updates problem |
Date: | 2001-03-19 22:57:51 |
Message-ID: | 3AB68EEF.24CBB445@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Tom Lane wrote:
>
> begin;
> select * from threads where forum_id = 1 and thread_id = 1 FOR UPDATE;
> update threads set views = views + 1 where forum_id = 1 and thread_id = 1;
> end;
>
> Note the FOR UPDATE to lock the row and the transaction wrapping to
> define the scope of the lock. Without this I'd expect you to lose
> some counter increments as a result of two processes doing the UPDATE
> at about the same time (both will read the old value of "views" and
> increment it by one).
Tom - Surely the update runs in its own transaction and will only ever
update a previously consistent value? If there is another transaction
concurrently updating it should block until the results are available?
I can see what you're getting at but for the example query it shouldn't
be necessary if I understand this right.
- Richard Huxton
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Eckermann | 2001-03-19 23:44:02 | Strange Type Mismatch on Insert |
Previous Message | Rick Delaney | 2001-03-19 22:10:45 | Accessing serials through rules |