Re: Select for update - Mailing list pgsql-sql

From Tom Lane
Subject Re: Select for update
Date
Msg-id 1549336.1622050610@sss.pgh.pa.us
Whole thread Raw
In response to Re: Select for update  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-sql
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Wed, May 26, 2021, 08:20 Yambu <hyambu@gmail.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



pgsql-sql by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Select for update
Next
From: Ron Clarke
Date:
Subject: Postgresql - Json syntax in INSERT RETURNING clause with INTO