Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ow4oW-0005wf-8f for pgsql-bugs@arkaria.postgresql.org; Fri, 18 Nov 2022 17:06:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ow4oV-00068d-4u for pgsql-bugs@arkaria.postgresql.org; Fri, 18 Nov 2022 17:06:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ow4oU-00066L-SZ for pgsql-bugs@lists.postgresql.org; Fri, 18 Nov 2022 17:06:02 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ow4oS-0000El-DS for pgsql-bugs@lists.postgresql.org; Fri, 18 Nov 2022 17:06:02 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 3270E5C035D; Fri, 18 Nov 2022 12:05:59 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Fri, 18 Nov 2022 12:05:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1668791159; x=1668877559; bh=F Eseuy4TghQmMRp/UQEceYFyONK9ry20YpFqA+BWQVc=; b=P9aYkAULTcQePeTBt VgQTNJJaqHCX/npu7FlbydVY44JtVNSrCPBanUcbY7nnM1KU4mqvrb58Iq00vew4 y5uKTszdSyMP6ZrLP3AEq8eRmf8KI8Ms/seM7ALWDLjDAXDv3d/uFR9KwWLuXrwg pv9upv7YjWsHucd4Xf7CXdaZ9DawB0fMMm9RlRd2UE+a3kaHMZwVnFeFDHOVnWIP 2NtXviINRfagoOz9RX0Fl3rYed/DVRJRNW/Fw6TzCP0Hn+hb8e5qBdCcC7rCtFTF hpQPSCEQT+exJ4TKo5veDBpMdqwuicuUkdEDdXoBlY7eIGWb1mnOq5trCfVHcotw wDhaw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrhedtgdelkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpeektdfhkeevudeugfeuleetkefgjeegkeeuudduueevuedv udffgffgteeihfdvfeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgpdgvnh htvghrphhrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 18 Nov 2022 12:05:58 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 1D2B439C; Fri, 18 Nov 2022 18:05:57 +0100 (CET) Date: Fri, 18 Nov 2022 18:05:57 +0100 From: Alvaro Herrera To: Marko Tiikkaja Cc: eugene.pliskin@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17689: Two UPDATE operators in common table expressions (CTE) perform not as expected Message-ID: <20221118170557.3ndokzwhilygtfq7@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2022-Nov-18, Marko Tiikkaja wrote: > This is a documented limitation: > > > Trying to update the same row twice in a single statement is not > > supported. Only one of the modifications takes place, but it is not > > easy (and sometimes not possible) to reliably predict which one. > > This also applies to deleting a row that was already updated in the > > same statement: only the update is performed. Therefore you should > > generally avoid trying to modify a single row twice in a single > > statement. In particular avoid writing WITH sub-statements that > > could affect the same rows changed by the main statement or a > > sibling sub-statement. The effects of such a statement will not be > > predictable. > > https://www.postgresql.org/docs/current/queries-with.html I wonder if we should try to detect the case, and raise an error instead of it resulting in undefined behavior. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/