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

From: Maiquel Grassi <grassi(at)hotmail(dot)com(dot)br>
To: Michał Kłeczek <michal(at)kleczek(dot)org>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: RE: New Window Function: ROW_NUMBER_DESC() OVER() ?
Date: 2024-01-16 20:11:04
Message-ID: CP8P284MB2496624FD09B4B1ECA672323EC732@CP8P284MB2496.BRAP284.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Przemysław Sztoch 2024-01-16 20:20:58 Re: UUID v7
Previous Message Jelte Fennema-Nio 2024-01-16 20:10:37 Re: UUID v7