Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdIRH-0006NW-Bm for pgsql-general@arkaria.postgresql.org; Tue, 18 Jun 2019 18:02:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdIRE-00014Z-NC for pgsql-general@arkaria.postgresql.org; Tue, 18 Jun 2019 18:02:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdIRE-000149-Bj for pgsql-general@lists.postgresql.org; Tue, 18 Jun 2019 18:02:32 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdIRB-0004nx-Bf for pgsql-general@postgresql.org; Tue, 18 Jun 2019 18:02:31 +0000 Received: by mail-wr1-x443.google.com with SMTP id v14so513086wrr.4 for ; Tue, 18 Jun 2019 11:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=b1cjwiez0EM3kQqmcwniRv4yqWhf8KHxb2Mk4Q/q9TY=; b=d2i7T2nZL8wXAgJK07Zceim0fmXTe8UDXa5Dexk1F4aU/jfyps/ZRMj/mlrEhOLQCp 0Y1D7yB+l/8f5cWoWoo4/Es0bleGmV6gwMDBsh0y7AWE+se2NpEar40Mcomiyi75pZd3 2nHFHT8a4pmf1RtTiGH8LRp0J4XQjUlEJtP2da8fs/ICJJgo9w3BldB1rWOkHvQcXOAx W3zVeumBOf7viEnK6OrPVoabEmFwEwUJCrZ2q01A+/lfvf1A+TaXJOq6UwX+n6E+0cab bfnFVRyNq5og6L1ZJGZ+PU7DW2Va7cu0IjC+PsDC3g56hqVTCDnA330e7a+WllfDhlVB 8V6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=b1cjwiez0EM3kQqmcwniRv4yqWhf8KHxb2Mk4Q/q9TY=; b=W6j2LyLDbqWAX773U1Aa00gZY5iqmc4k4eqG6FVgNd9+sPG48heOcqhUaJni0J8mzn RJf58hJjWlma4hrteuJuTY/EMqzFOxyS/idB+SrCai3+2v1EWea+vgzfzHI9kFuXLKSF IznrIbmXjB1tuOKKRx0bVzcchiLzhEzrJEBcOHQdrl+xeHhtaTL+Ax6p0FhzQMvZbqXE BkwM13FoQ80D2D6OdDIe4KR8YNKhJDGms6U6sUREZ7bZ6rstZu9arE16LPXvX8cQSQbf sPnfWAYG9WSTZSp7ruUoYL5AAakl5seaTC3MwG0VBGaIfxQdyqaM7ggr4FJf+I0KWCHQ p5aQ== X-Gm-Message-State: APjAAAVXAk4OiMQSzX6+WqAWEcbTUxZblsvDLeWuMVZE7Pnjx+2JRwzg E09ZPsC8P8m1He/pG9nKNuG80fne6x0= X-Google-Smtp-Source: APXvYqwdipfuTZJZJSebRJB0RtAiM/yoPVxQ7PDI3VLdfC9c5s2A1r72k5jI8kRhthuUVvaxP1Ytnw== X-Received: by 2002:a5d:45d0:: with SMTP id b16mr14726952wrs.209.1560880946668; Tue, 18 Jun 2019 11:02:26 -0700 (PDT) Received: from [192.168.1.5] (178-224-203.dynamic.cyta.gr. [178.59.224.203]) by smtp.gmail.com with ESMTPSA id g71sm4824331wmg.7.2019.06.18.11.02.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jun 2019 11:02:25 -0700 (PDT) From: Rob Nikander Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: delete inside for plpgsql loop on same relation? Message-Id: Date: Tue, 18 Jun 2019 21:02:24 +0300 To: Postgres General X-Mailer: Apple Mail (2.3445.9.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, Are there guarantees about how this plpgsql behaves? It=E2=80=99s = 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=E2=80=99t = interfere.=20 for row in select * from some_stuff loop delete from some_stuff where =E2=80=A6 ... end loop; I=E2=80=99m using a temporary table of =E2=80=9Cthings to process=E2=80=9D= and looping over it, deleting the ones as I go. I don=E2=80=99t see anything mentioned here: = https://www.postgresql.org/docs/11/plpgsql-control-structures.html#PLPGSQL= -RECORDS-ITERATING Rob=