pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Wiwwo Staff <wiwwo@wiwwo.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: FOR UPDATE SKIP LOCKED and get locked row/avoid updating other row(s)
Date: Tue, 13 Feb 2024 14:59:26 +0100
Message-ID: <6995ad23a1e48f612b43c19f015cc88659bcd000.camel@cybertec.at> (raw)
In-Reply-To: <CAD1W9HUrmzSRYLeBSHf3gL7G5pSW9AA5BMdYQq-rg4xK8tHe1w@mail.gmail.com>
References: <CAD1W9HUrmzSRYLeBSHf3gL7G5pSW9AA5BMdYQq-rg4xK8tHe1w@mail.gmail.com>

On Tue, 2024-02-13 at 11:17 +0000, Wiwwo Staff wrote:
> I am implementing a queue using PostgreSQL.
> I am of course using "FOR UPDATE SKIP LOCKED".
> 
> Is there any way I can tell PostgreSQL to only "operate" on the locked row, and/or a way to reference it?
> 
> Some explanations of what I mean:
>  * I have a table with N rows
>  * I lock row X with a PG Function, in transaction 1
>  * I do something in my code, using transaction 2
>  * I update the status of row X with a PG Function, in transaction 1
> In last step, I update the row X status, passing my function the ID of this row X.
> But, nothing stops me from updating row Y in the queue table, for whatever reason.
> 
> My question again: any way to force a "Just update the row X you locked before, and nothing else/more?"

I don't think there is a way to enforce that.  Your application code
has to do the right thing.

Yours,
Laurenz Albe





view thread (4+ messages)  latest in thread

Message-ID: <6995ad23a1e48f612b43c19f015cc88659bcd000.camel@cybertec.at>
Permalink:  ../6995ad23a1e48f612b43c19f015cc88659bcd000.camel@cybertec.at/
Also on:    postgresql.org/message-id/6995ad23a1e48f612b43c19f015cc88659bcd000.camel@cybertec.at

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, wiwwo@wiwwo.com
  Subject: Re: FOR UPDATE SKIP LOCKED and get locked row/avoid updating other row(s)
  In-Reply-To: <6995ad23a1e48f612b43c19f015cc88659bcd000.camel@cybertec.at>
  References: <CAD1W9HUrmzSRYLeBSHf3gL7G5pSW9AA5BMdYQq-rg4xK8tHe1w@mail.gmail.com> <6995ad23a1e48f612b43c19f015cc88659bcd000.camel@cybertec.at>

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

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