agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Yambu <hyambu@gmail.com>
Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
Subject: Re: Select for update
Date: Wed, 26 May 2021 13:36:50 -0400
Message-ID: <1549336.1622050610@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwaPC=DJA2LzfyhtMr-VAo55wPrwMBKQONNJ3W7Rws365A@mail.gmail.com>
References: <CALhHtcA1f=mVPZ9adDTcCX2E0Zo57ZfMqs4ej=5G+OQA6N-zTA@mail.gmail.com>
	<CAKFQuwYiJyPu2vezTJHzDNqM0+Er-NMf_doDjhiZmWToVhJttQ@mail.gmail.com>
	<CALhHtcDCyQxmSmGPF5du=Gz4fZU0eq22WbcwjLHp8Z4UjOTT-g@mail.gmail.com>
	<CAKFQuwaPC=DJA2LzfyhtMr-VAo55wPrwMBKQONNJ3W7Rws365A@mail.gmail.com>

"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





view thread (17+ messages)

Message-ID: <1549336.1622050610@sss.pgh.pa.us>
Permalink:  ../1549336.1622050610@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1549336.1622050610@sss.pgh.pa.us

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, hyambu@gmail.com, pgsql-sql@lists.postgresql.org
  Subject: Re: Select for update
  In-Reply-To: <1549336.1622050610@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox