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.96) (envelope-from ) id 1x6ahh-000K8r-25 for pgsql-docs@arkaria.postgresql.org; Tue, 15 Sep 2026 21:28:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x6ahg-003ZNg-16 for pgsql-docs@arkaria.postgresql.org; Tue, 15 Sep 2026 21:28:36 +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.96) (envelope-from ) id 1x6ahg-003ZNX-0N for pgsql-docs@lists.postgresql.org; Tue, 15 Sep 2026 21:28:36 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x6ahc-00000000e7h-2FkA for pgsql-docs@lists.postgresql.org; Tue, 15 Sep 2026 21:28:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2026010100; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description; bh=prQedybb0lBAuIMzC4LcdYgRMb0iXp1KVZEGPoYIzb0=; b=wg6Qh sL+nx62geRCmq5voWIyMV/at0wcLHwTTE3OuGzXqwkr+89o4NUdR5PXGDGrqVi978sADBQ/4tckxY 61PW5xFWFOl6paIZ3H233W6cZdUwYcy3y5P3gd3BdN/RAg43oW3ExT8zKSTxQm/XVgEIqngbl7u7r Uyi3TkZ5tWIcJgpSyIsEWNaF5Q+Ki/OPFoo0p724pw2sr8U4dpzgOBQTjwtL83ffmEb7qae4608VT RvBbGwSabo6zCMHlRZPN5GSvzyX+qTw4BQunBUE/9EhTdPH54tRbI1HhHaF8BLN71eIe+TJzhZQj7 PVG60JPPa2SbjQZ4E25fO8vCCrNDg==; Received: from bruce by momjian.us with local (Exim 4.98.2) (envelope-from ) id 1x6ahb-00000000Qzf-1sLx; Tue, 15 Sep 2026 17:28:31 -0400 Date: Tue, 15 Sep 2026 17:28:31 -0400 From: Bruce Momjian To: y.saburov@gmail.com, pgsql-docs@lists.postgresql.org Subject: Re: 4.2.7. Aggregate Expressions Message-ID: References: <178784080621.1060526.4544192651418189612@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="lXZ3FJDUs0lZTRJz" Content-Disposition: inline In-Reply-To: <178784080621.1060526.4544192651418189612@wrigleys.postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --lXZ3FJDUs0lZTRJz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Aug 27, 2026 at 02:26:46PM +0000, PG Doc comments form wrote: > The following documentation comment has been logged on the website: > > Page: https://www.postgresql.org/docs/18/sql-expressions.html > Description: > > Can you add a code block with an example? > > Perhaps something like this: > > ```psql > db=# WITH vals (f1) AS ( VALUES (1),(3),(4),(3),(2),(null) ) > SELECT count(*), count(f1), COUNT(DISTINCT f1) FROM vals; > > count | count | count > -------+-------+------- > 6 | 5 | 4 > (1 row) > ``` > > After: > > >> For example, count(*) returns the total number of input rows; count(f1) > returns the number of input rows in which f1 is not null, since count > ignores null values; and count(distinct f1) returns the number of distinct > non-null values of f1. I see your point that this could be clearer. How is this patch? -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Do not let urgent matters crowd out time for investment in the future. --lXZ3FJDUs0lZTRJz Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="agg_null.diff" diff --git a/doc/src/sgml/syntax.sgml b/doc/src/sgml/syntax.sgml index 67482996861..a697218c8b3 100644 --- a/doc/src/sgml/syntax.sgml +++ b/doc/src/sgml/syntax.sgml @@ -1602,11 +1602,19 @@ sqrt(2) - For example, count(*) yields the total number - of input rows; count(f1) yields the number of - input rows in which f1 is non-null, since - count ignores nulls; and - count(distinct f1) yields the number of + For example, in this query: + +WITH vals (f1) AS ( VALUES (1),(3),(4),(3),(2),(null) ) +SELECT count(*) AS total, count(f1) AS non_null, COUNT(DISTINCT f1) AS distinct +FROM vals; + total | non_null | distinct +-------+----------+---------- + 6 | 5 | 4 + + total yields the total number of input rows; + non_null yields the number of input rows in which + f1 is non-null, since count + ignores nulls; and distinct yields the number of distinct non-null values of f1. --lXZ3FJDUs0lZTRJz--