Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sm1Hp-002dHW-92 for pgsql-docs@arkaria.postgresql.org; Thu, 05 Sep 2024 01:27:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sm1Hn-000SBO-PW for pgsql-docs@arkaria.postgresql.org; Thu, 05 Sep 2024 01:27:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sm1Hn-000SBG-Hw for pgsql-docs@lists.postgresql.org; Thu, 05 Sep 2024 01:27:47 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sm1Hl-000CyB-Mu for pgsql-docs@lists.postgresql.org; Thu, 05 Sep 2024 01:27:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4851Rf3h1729421; Wed, 4 Sep 2024 21:27:41 -0400 From: Tom Lane To: Kirk Parker cc: pgsql-docs@lists.postgresql.org Subject: Re: Behavior of ON DELETE CASCADE in CTEs In-reply-to: References: Comments: In-reply-to Kirk Parker message dated "Wed, 04 Sep 2024 18:23:25 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1729419.1725499661.1@sss.pgh.pa.us> Date: Wed, 04 Sep 2024 21:27:41 -0400 Message-ID: <1729420.1725499661@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Kirk Parker writes: > It appears that in With-queries (CTE) the ON CASCADE DELETE deletions > happen at the very end of the entire statement. I have two questions about > this: > (1) Is this a correct observation? > (2) Is this intentional behavior, or only an accident of the implementation? I believe it's required by SQL spec. Or more accurately, the spec says that constraint-triggered actions happen either at the end of the statement or the end of the transaction, depending on whether you set them as "deferred". regards, tom lane