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 1taIDq-000VJk-2Y for pgsql-docs@arkaria.postgresql.org; Tue, 21 Jan 2025 17:39:30 +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 1taIDp-002Zkr-5T for pgsql-docs@arkaria.postgresql.org; Tue, 21 Jan 2025 17:39:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1taIDo-002Zki-Up for pgsql-docs@lists.postgresql.org; Tue, 21 Jan 2025 17:39:28 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1taIDm-000laF-2Z for pgsql-docs@lists.postgresql.org; Tue, 21 Jan 2025 17:39:28 +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 50LHdPng3359765; Tue, 21 Jan 2025 12:39:25 -0500 From: Tom Lane To: oselemg@gmail.com cc: pgsql-docs@lists.postgresql.org Subject: Re: Typo on tutorial window page In-reply-to: <173737973383.1070.1832752929070067441@wrigleys.postgresql.org> References: <173737973383.1070.1832752929070067441@wrigleys.postgresql.org> Comments: In-reply-to PG Doc comments form message dated "Mon, 20 Jan 2025 13:28:53 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3359763.1737481165.1@sss.pgh.pa.us> Date: Tue, 21 Jan 2025 12:39:25 -0500 Message-ID: <3359764.1737481165@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Doc comments form writes: > EXPECTED: > As shown here, the rank function produces a numerical rank for each distinct > PARTITION BY value in the current row's partition, using the order defined > by the ORDER BY clause. rank needs no explicit parameter, because its > behavior is entirely determined by the OVER clause. > ACTUAL: > As shown here, the rank function produces a numerical rank for each distinct > ORDER BY value in the current row's partition, using the order defined by > the ORDER BY clause. rank needs no explicit parameter, because its behavior > is entirely determined by the OVER clause. Hmm, I think the current text is correct, or at least more nearly correct than what you suggest. Look at the example: SELECT depname, empno, salary, rank() OVER (PARTITION BY depname ORDER BY salary DESC) FROM empsalary; depname | empno | salary | rank -----------+-------+--------+------ develop | 8 | 6000 | 1 develop | 10 | 5200 | 2 develop | 11 | 5200 | 2 develop | 9 | 4500 | 4 develop | 7 | 4200 | 5 personnel | 2 | 3900 | 1 personnel | 5 | 3500 | 2 sales | 1 | 5000 | 1 sales | 4 | 4800 | 2 sales | 3 | 4800 | 2 (10 rows) The ranks are separate within each partition (depname), and within a partition rows having the same salary get the same rank. regards, tom lane