agora inbox for pgsql-docs@postgresql.org  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: oselemg@gmail.com
Cc: pgsql-docs@lists.postgresql.org
Subject: Re: Typo on tutorial window page
Date: Tue, 21 Jan 2025 12:39:25 -0500
Message-ID: <3359764.1737481165@sss.pgh.pa.us> (raw)
In-Reply-To: <173737973383.1070.1832752929070067441@wrigleys.postgresql.org>
References: <173737973383.1070.1832752929070067441@wrigleys.postgresql.org>

PG Doc comments form <noreply@postgresql.org> 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:

<programlisting>
SELECT depname, empno, salary,
       rank() OVER (PARTITION BY depname ORDER BY salary DESC)
FROM empsalary;
</programlisting>

<screen>
  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)
</screen>

The ranks are separate within each partition (depname), and
within a partition rows having the same salary get the
same rank.

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <3359764.1737481165@sss.pgh.pa.us>
Permalink:  ../3359764.1737481165@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3359764.1737481165@sss.pgh.pa.us

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, oselemg@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: Typo on tutorial window page
  In-Reply-To: <3359764.1737481165@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox