Re: Select for update

From: Yambu <hyambu(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Select for update
Date: 2021-05-26 15:19:39
Message-ID: CALhHtcDCyQxmSmGPF5du=Gz4fZU0eq22WbcwjLHp8Z4UjOTT-g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

This update, sorry forgot to include FOR UPDATE part

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;

On Wed, May 26, 2021 at 2:27 PM David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

>
> On Wednesday, May 26, 2021, Yambu <hyambu(at)gmail(dot)com> wrote:
>
>> Hello
>>
>> May i know if i run the update below if the row select in SELECT FOR
>> UPDATE will not be available for selection during update?
>>
>> UPDATE table1 set status_id=13 WHERE id= ( SELECT id FROM table2 where
>> status_id=1 LIMIT 1) RETURNING id into v_id;
>>
>
> Which update? The way it works is by locking - Ihe row is available but
> locked and may require waiting.
>
> David J.
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message David G. Johnston 2021-05-26 17:06:49 Re: Select for update
Previous Message David G. Johnston 2021-05-26 12:27:24 Re: Select for update