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 1mFjAC-00010i-Ez for pgsql-general@arkaria.postgresql.org; Mon, 16 Aug 2021 20:24:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mFjAA-0004nT-Ds for pgsql-general@arkaria.postgresql.org; Mon, 16 Aug 2021 20:24:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mFjAA-0004nL-5F for pgsql-general@lists.postgresql.org; Mon, 16 Aug 2021 20:24:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mFjA8-00054Q-5U for pgsql-general@lists.postgresql.org; Mon, 16 Aug 2021 20:24:49 +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 17GKOkoJ987977; Mon, 16 Aug 2021 16:24:46 -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: References: Comments: In-reply-to "David G. Johnston" message dated "Mon, 16 Aug 2021 13:16:12 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <987975.1629145486.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 16 Aug 2021 16:24:46 -0400 Message-ID: <987976.1629145486@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "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 > You can get it to work via a subquery/FROM clause computation. That it > doesn't work directly in the SET clause I don't know off-hand, but most > likely the development and runtime cost of making it work isn't worth th= e > benefit. 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. >> Why aren't window functions allowed in GENERATED columns? > Because the expressions allowed in GENERATED can only immutably referenc= e > other columns in the same row. The underlying rationale is probably qui= te > similar to the UPDATE comment above. Yeah --- GENERATED is supposed to be immutable, and there's about 0% chance that anything involving a subquery or window function would really be immutable. I think there are implementation issues too, but they're not worth getting into given that point. regards, tom lane