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

From Maiquel Grassi
Subject RE: New Window Function: ROW_NUMBER_DESC() OVER() ?
Date
Msg-id CP8P284MB2496624FD09B4B1ECA672323EC732@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM
Whole thread Raw
In response to Re: New Window Function: ROW_NUMBER_DESC() OVER() ?  (Michał Kłeczek <michal@kleczek.org>)
List pgsql-hackers
You can do:

-(ROW_NUMBER() OVER ()) AS descending

(note “-“ in front)

I don't have a base column to use for "order by,"

I think that’s the main issue: what (semantically) does row_number() mean in that case? You could equally well generate random numbers?

--//--

What I want to do is inverse the enumeration using a simple solution. I want to look at the enumeration of the dataset list from bottom to top, not from top to bottom. I don't want to reverse the sign of the integers. The generated integers in output remain positive.The returned dataset can be from any query. What I need is exactly the opposite of row_number().


count(*) over() - row_number() + 1 works.

But I think for a large volume of data, its performance will be inferior to the suggested row_number_desc() over(). I may be very wrong, so I will test it.

Maiquel.

pgsql-hackers by date:

Previous
From: Jelte Fennema-Nio
Date:
Subject: Re: UUID v7
Next
From: Przemysław Sztoch
Date:
Subject: Re: UUID v7