RE: concurrent updates problem

From: "Hiroshi Inoue" <Inoue(at)tpf(dot)co(dot)jp>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <mwaples(at)waples(dot)net>, <pgsql-general(at)postgresql(dot)org>, "Richard Huxton" <dev(at)archonet(dot)com>
Subject: RE: concurrent updates problem
Date: 2001-03-20 00:23:02
Message-ID: EKEJJICOHDIEMGPNIFIJGEFNDOAA.Inoue@tpf.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: Tom Lane
>
> >> 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.

ISTM this is not the case that 'FOR UPDATE' is required.

> 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).
>

If this is true, it's really a serious bug and must be fixed.

regards,
Hiroshi Inoue

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2001-03-20 00:26:53 Re: Strange Type Mismatch on Insert
Previous Message Bruce Momjian 2001-03-20 00:17:36 Re: [GENERAL] Re: temp table creation