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.94.2) (envelope-from ) id 1taIhg-000asL-16 for pgsql-docs@arkaria.postgresql.org; Tue, 21 Jan 2025 18:10:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1taIhf-003CbX-4T for pgsql-docs@arkaria.postgresql.org; Tue, 21 Jan 2025 18:10:19 +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.94.2) (envelope-from ) id 1taIhe-003CbP-Th for pgsql-docs@lists.postgresql.org; Tue, 21 Jan 2025 18:10:18 +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.96) (envelope-from ) id 1taIhb-000lD5-30 for pgsql-docs@lists.postgresql.org; Tue, 21 Jan 2025 18:10:18 +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 50LIAEgE3363257; Tue, 21 Jan 2025 13:10:14 -0500 From: Tom Lane To: "David G. Johnston" cc: oselemg@gmail.com, pgsql-docs@lists.postgresql.org Subject: Re: Typo on tutorial window page In-reply-to: References: <173737973383.1070.1832752929070067441@wrigleys.postgresql.org> <3359764.1737481165@sss.pgh.pa.us> Comments: In-reply-to "David G. Johnston" message dated "Tue, 21 Jan 2025 10:55:31 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3363255.1737483014.1@sss.pgh.pa.us> Date: Tue, 21 Jan 2025 13:10:14 -0500 Message-ID: <3363256.1737483014@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > I was going to write basically that but something feels off to me. Maybe > something like this: > "As shown here, the rank function produces a numerical ranking within each > partition, using the order defined by the ORDER BY clause. Ranking assigns > the same rank to all rows that tie according to the order by criteria, > while still incrementing the rank counter. Thus there are gaps in the > serial numbering. These can be removed by instead using the dense_rank > window function. Ties can instead be given their own unique value by using > the row_number window function. In all these cases, as the window function > is effectively just counting rows, the function itself has no input > parameter." > If we don't want to get into that level of nuance in the tutorial I suggest > we use the row_number() window function instead of rank, and just say > because we count rows no parameter is needed. Yeah, I was wondering if it'd be worth bringing up dense_rank, but decided "probably not". I like your idea of switching the example to use row_number to simplify things. What would the text be then? Perhaps As shown here, the row_number function assigns sequential numbers to the rows within each partition, in the order defined by the ORDER BY clause (with tied rows numbered in an unspecified order). row_number needs no explicit parameter, because its behavior is entirely determined by the OVER clause. regards, tom lane