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.98.2) (envelope-from ) id 1x7CDo-00000000BLa-2FJB for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Sep 2026 13:32:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x7CDn-00000004TAo-2aZE for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Sep 2026 13:32:15 +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.98.2) (envelope-from ) id 1x7CDn-00000004TAg-1LxW for pgsql-hackers@lists.postgresql.org; Thu, 17 Sep 2026 13:32:15 +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.98.2) (envelope-from ) id 1x7CDg-000000011AF-1cyH for pgsql-hackers@postgresql.org; Thu, 17 Sep 2026 13:32:15 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 68HDViNb636821; Thu, 17 Sep 2026 09:31:44 -0400 From: Tom Lane To: Robert Haas cc: Jeevan Chalke , PostgreSQL Hackers , Vik Fearing , Isaac Morland Subject: Re: ON EMPTY clause for aggregate and window functions In-reply-to: References: Comments: In-reply-to Robert Haas message dated "Thu, 17 Sep 2026 09:16:11 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <636819.1789651904.1@sss.pgh.pa.us> Date: Thu, 17 Sep 2026 09:31:44 -0400 Message-ID: <636820.1789651904@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > This seems pretty useless -- the new syntax is more work for us to > maintain, and doesn't really add any value over just using COALESCE. It could add value, in scenarios where substitute-for-NULL doesn't give quite the behavior you want. But that's not so for the two aggregates the spec has bothered to define this for, and I'm having a hard time coming up with an aggregate for which it would be so. If somebody actually did have an aggregate that could return null for more than zero input rows, they could always do CASE WHEN count(x) > 0 THEN frobnitz(x) ELSE value_for_zero_rows END which has the extra benefit that you can choose "count(x)" or "count(*)" depending on your desires for what to do with null inputs. > To be clear, I expect to lose this argument on the grounds that > apparently this syntax is in the spec and therefore we ought to > support it. But I don't understand why the spec -- or we -- should > spend time inventing new ways to spell existing behaviors. That just > seems confusing (and this particular choice of syntax seems > extra-confusing). Yes, this choice of syntax sucks pretty badly. In the COALESCE spelling, it's crystal clear that the substitute value is not an aggregate argument and so is evaluated at most once (per group); there's no need for gamesmanship around restricting it to be a constant. I'd be totally fine with rejecting this as a frammish we do not care to support. regards, tom lane