pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Nikander <rob.nikander@gmail.com>
To: Postgres General <pgsql-general@postgresql.org>
Subject: delete inside for plpgsql loop on same relation?
Date: Tue, 18 Jun 2019 21:02:24 +0300
Message-ID: <C12E9EA5-5B1A-44C7-9A4D-F01F12261A07@gmail.com> (raw)

Hi,

Are there guarantees about how this plpgsql behaves? It’s deleting from a table while it loops over it. So far it seems like the delete is logically after the select, as I hoped, and doesn’t interfere. 

    for row in select * from some_stuff loop
        delete from some_stuff where …
        ...
    end loop;

I’m using a temporary table of “things to process” and looping over it, deleting the ones as I go.

I don’t see anything mentioned here: https://www.postgresql.org/docs/11/plpgsql-control-structures.html#PLPGSQL-RECORDS-ITERATING

Rob




view thread (2+ messages)  latest in thread

Message-ID: <C12E9EA5-5B1A-44C7-9A4D-F01F12261A07@gmail.com>
Permalink:  ../C12E9EA5-5B1A-44C7-9A4D-F01F12261A07@gmail.com/
Also on:    postgresql.org/message-id/C12E9EA5-5B1A-44C7-9A4D-F01F12261A07@gmail.com

 · 

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: rob.nikander@gmail.com
  Subject: Re: delete inside for plpgsql loop on same relation?
  In-Reply-To: <C12E9EA5-5B1A-44C7-9A4D-F01F12261A07@gmail.com>
  References: <C12E9EA5-5B1A-44C7-9A4D-F01F12261A07@gmail.com>

* 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