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 1pn0MA-0005wz-Fb for pgsql-general@arkaria.postgresql.org; Thu, 13 Apr 2023 17:03:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pn0M9-0005Gp-2O for pgsql-general@arkaria.postgresql.org; Thu, 13 Apr 2023 17:03:33 +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 1pn0M8-0005Ga-O0 for pgsql-general@lists.postgresql.org; Thu, 13 Apr 2023 17:03:32 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pn0M6-002gCO-3Q for pgsql-general@lists.postgresql.org; Thu, 13 Apr 2023 17:03:32 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id DFEFB32009C2; Thu, 13 Apr 2023 13:03:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 13 Apr 2023 13:03:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1681405407; x=1681491807; bh=0rALxSs0P3jcpneVtm9a6hWNHYSw1o5oWrt B78OODGE=; b=jcNGGDquLkLnXJD9wfuTXT2XGLmd41gSmWSDPkrKZ2VNP+KUX7w 3McVc9ssWOaNTFU7bV+DF4WKb/2vabBT41JXmIzA2ud/pkJMW6oCsDeGqy7XCLZi VXW4ip7F7bpbYIZWHkib147OYZhgg8JxB81ENLxIvER3AHaLz+6k+Bp8VqwEndqN +vZVGpy9/RrcD4wHWikQxm4mH9zCF6yPf8CO1S4VsuPJuflYwYS2VMT6eqs01Q8R DIP2Pp8K3iG4LDcxH3iqh/FvQyTUmrBpM1j7MAkZCPw02aQsz5oz1I7N2wPvHEqF a9KZcU8JnjftT+WZpwhMnj7Ey0ekHhrtYHw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1681405407; x=1681491807; bh=0rALxSs0P3jcpneVtm9a6hWNHYSw1o5oWrt B78OODGE=; b=A9eXEBDFGWNsCLtbSZxJShhfpyFD3HlED5RjunIa7l8ga0v5CaW 0QFwE3l5bGjpIb3unPKyomC3/mZz5Ysrx40Eqi5GdaLl5UWJj6iUYTD+u72Wi1W2 +pxm3vY0nTChhyN6CRIJx8uKSEvI0XGVboa4FfBfU8Ay0bYy2CWjk/yRR3WhFegV 9SJK/DJ3CTGA5ygQbu74ExpzIyxCqcsLdCjfpTVwperuJhX/KR0KPAXpkQIPaPN4 o4L41QBAfHw9BDCwZeWbbIgVPDwJPasSx4fVDWbI4uaRdR+fKC3/Ec38tE0b83gF LeyHgZlv+81CHJtIFDef5G033BqJAbRkogQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdekkedguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttdefjeenucfhrhhomheptegu rhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrd gtohhmqeenucggtffrrghtthgvrhhnpeehudfgtefhtedtheeiveetueektdejvdfhveek gfdufeegveetuddvuedvgeeggeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 13 Apr 2023 13:03:26 -0400 (EDT) Message-ID: <610e53b5-aba2-d232-9448-765327b88431@aklaver.com> Date: Thu, 13 Apr 2023 10:03:25 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: Unexpected behavior when combining `generated always` columns and update rules Content-Language: en-US To: Ciprian Craciun , Tom Lane , "David G. Johnston" Cc: "pgsql-general@lists.postgresql.org" References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/13/23 09:27, Ciprian Craciun wrote: > On Thu, Apr 13, 2023 at 5:32 PM David G. Johnston > wrote: >> ALSO rules behave like before triggers, not after triggers. The original command is appended to the end of the list of commands, not the start. > > > As Tom observed, the documentation states that in case of update > rules, the original query is executed at the end. > > However, regardless of the order of the execution between new and > original query, as per the documentation the `new` table should > contain the new values regardless. > > In fact, from my example above, one can see that the `y.x` is properly > updated with the new value, meanwhile the `y.d` is the previous one > (i.e. `old.d`). > > So, based on these observations, I think that `generated always` > columns are actually computed on insertion, and thus they are not > reflected in `new` on rules. Just realized we may have both being saying the same thing. That your '...actually computed on insertion,...' meant not just for an INSERT but for any change in the data. In other words when the original query actually ran. > > Ciprian. > > -- Adrian Klaver adrian.klaver@aklaver.com