Re: New Window Function: ROW_NUMBER_DESC() OVER() ?

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Maiquel Grassi <grassi(at)hotmail(dot)com(dot)br>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: New Window Function: ROW_NUMBER_DESC() OVER() ?
Date: 2024-01-16 16:24:30
Message-ID: CAKFQuwaGhHJTsAR4k0Q_fdnerA-DkRw1HruqyW2W_6wGA+W2Gw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tuesday, January 16, 2024, Maiquel Grassi <grassi(at)hotmail(dot)com(dot)br> wrote:

> Hello David, how are you?
>
> Firstly, I apologize if I wasn't clear in what I intended to propose. I
> used a very specific example here, and it wasn't very clear what I really
> wanted to bring up for discussion.
>
> I understand that it's possible to order the "returned dataset" using
> "order by ... desc."
>
>
It is, but it is also possible to order a window frame/partition by
specifying order by in the over clause. Which is what I showed, and what
you should try to use. That orders the enumeration, you can still order,
or not, the output dataset.

> I don't have a base column to use for "order by," and I also can't use
> CTID column.
>

Then you really don’t have an ordering in the data itself. This is unusual
and not really worth adding a new function to deal with.

>
> How can I do this without using my reversed enumeration "row_number desc"
> function?
>

Count() over() - row_number() over()

Please don’t top-post replies, in-line and trim like I’m doing.

David J.

P.s. if you really don’t care about logical order you probably should just
let your front-end deal with it.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2024-01-16 16:25:05 Re: index prefetching
Previous Message feichanghong 2024-01-16 16:21:11 Re: "ERROR: could not open relation with OID 16391" error was encountered when reindexing