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 1mFk7T-0002Wb-Lm for pgsql-general@arkaria.postgresql.org; Mon, 16 Aug 2021 21:26:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mFk7Q-0002le-Ld for pgsql-general@arkaria.postgresql.org; Mon, 16 Aug 2021 21:26:04 +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 1mFk7Q-0002lQ-Cw for pgsql-general@lists.postgresql.org; Mon, 16 Aug 2021 21:26:04 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mFk7J-0003ea-0I for pgsql-general@lists.postgresql.org; Mon, 16 Aug 2021 21:26:03 +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 17GLPoEP1025333; Mon, 16 Aug 2021 17:25:50 -0400 From: Tom Lane To: "David G. Johnston" cc: =?UTF-8?B?UMOzbCBVYSBMYW/DrW5lY2jDoWlu?= , PostgreSQL General Subject: Re: Using a TRIGGER with window functions. In-reply-to: <987976.1629145486@sss.pgh.pa.us> References: <987976.1629145486@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 16 Aug 2021 16:24:46 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1025331.1629149150.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 16 Aug 2021 17:25:50 -0400 Message-ID: <1025332.1629149150@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > "David G. Johnston" writes: >> On Sun, Aug 15, 2021 at 1:24 AM P=C3=B3l Ua Lao=C3=ADnech=C3=A1in wrote: >>> Why are window functions now allowed in UPDATEs > I suspect the error check was just copied from the aggregate-function > case. It's clear why we can't put aggregates in UPDATE: there'd no > longer be a one-to-one correspondence with original rows. But that > argument doesn't hold for window functions, so at least in principle > it seems like we could allow it. The utility doesn't seem very high > though, so if it takes more work than "delete the error check" I'm > not sure anyone will care to bother. Out of curiosity, I did spend a few minutes poking at this, and as I feared it's not all that trivial. I think that the planner and executor might mostly Just Work, but there are various gaps in the parser. One interesting point is that the UPDATE syntax has no provision for a WINDOW clause, so there'd be no way to share window definitions across different window functions. While that's not exactly a deal-breaker, it'd be weird compared to how things work in SELECT. Would we be willing to go to the trouble of adding such a clause to the syntax? I dunno; it'd certainly enlarge the footprint of a patch for this by a lot. regards, tom lane