Re: concurrent updates problem

Поиск
Список
Период
Сортировка
От Jan Ploski
Тема Re: concurrent updates problem
Дата
Msg-id 5394851.985025083103.JavaMail.jpl@remotejava
обсуждение исходный текст
Ответ на concurrent updates problem  (mwaples@waples.net)
Ответы Re: concurrent updates problem
pg_dump problem
Список pgsql-general
On Mon, Mar 19, 2001 at 11:12:01AM -0500, Tom Lane wrote:
> >> I have on a web application
> >> update threads set views = views + 1 where forum_id = 1 and thread_id = 1
>
> It should work to do
>
> 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).

But the one-line version without select for update is equivalent, right?
That is, a single UPDATE statement is atomic? According to my test
(with 3 Java threads making a total of 15000 updates that way), it is:
no single update lost in the process.

-JPL

В списке pgsql-general по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Win Nt setup help please
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Cant connect if -B 1024 was set to postmaster