Re: New Window Function: ROW_NUMBER_DESC() OVER() ? - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: New Window Function: ROW_NUMBER_DESC() OVER() ?
Date
Msg-id CAKFQuwaGhHJTsAR4k0Q_fdnerA-DkRw1HruqyW2W_6wGA+W2Gw@mail.gmail.com
Whole thread Raw
In response to RE: New Window Function: ROW_NUMBER_DESC() OVER() ?  (Maiquel Grassi <grassi@hotmail.com.br>)
Responses RE: New Window Function: ROW_NUMBER_DESC() OVER() ?
List pgsql-hackers
On Tuesday, January 16, 2024, Maiquel Grassi <grassi@hotmail.com.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.

pgsql-hackers by date:

Previous
From: "feichanghong"
Date:
Subject: Re: "ERROR: could not open relation with OID 16391" error was encountered when reindexing
Next
From: Tomas Vondra
Date:
Subject: Re: index prefetching