Re: Typo on tutorial window page - Mailing list pgsql-docs

From David G. Johnston
Subject Re: Typo on tutorial window page
Date
Msg-id CAKFQuwaYf8E5oB0t5VCAJZHeJ01XjWH0JKVhASruhSaBNiMOSA@mail.gmail.com
Whole thread Raw
In response to Re: Typo on tutorial window page  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Typo on tutorial window page
List pgsql-docs
On Tue, Jan 21, 2025 at 10:39 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
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.

Hmm, I think the current text is correct, or at least more nearly
correct than what you suggest.

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


 Sorry for the empty email - finger spasm hit send.

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.

David J.

pgsql-docs by date:

Previous
From: Олег Семенов
Date:
Subject: Re: Typo on tutorial window page
Next
From: Tom Lane
Date:
Subject: Re: Typo on tutorial window page