delete inside for plpgsql loop on same relation? - Mailing list pgsql-general

From Rob Nikander
Subject delete inside for plpgsql loop on same relation?
Date
Msg-id C12E9EA5-5B1A-44C7-9A4D-F01F12261A07@gmail.com
Whole thread Raw
Responses Re: delete inside for plpgsql loop on same relation?
List pgsql-general
Hi,

Are there guarantees about how this plpgsql behaves? It’s deleting from a table while it loops over it. So far it seems
likethe 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


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Is array_append O(n)?
Next
From: Michael Curry
Date:
Subject: Re: perf tuning for 28 cores and 252GB RAM