Re: Select for update

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Yambu <hyambu(at)gmail(dot)com>, pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Select for update
Date: 2021-05-26 17:36:50
Message-ID: 1549336.1622050610@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Wed, May 26, 2021, 08:20 Yambu <hyambu(at)gmail(dot)com> wrote:
>> UPDATE table1 set status_id=13 WHERE id= ( SELECT id FROM table2 where
>> status_id=1 LIMIT 1 *FOR UPDATE*) RETURNING id into v_id;

> I don't think there is a point in saying for update when you are executing
> an update command.

The FOR UPDATE is in a subselect, so what it's doing is locking
rows of table2. That seems fairly sensible if what you want to
do is make sure those rows don't change before the UPDATE
commits.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Ron Clarke 2021-05-28 18:32:45 Postgresql - Json syntax in INSERT RETURNING clause with INTO
Previous Message David G. Johnston 2021-05-26 17:06:49 Re: Select for update