nth_value out of more than n values returns null

From: Guyren Howe <guyren(at)gmail(dot)com>
To: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: nth_value out of more than n values returns null
Date: 2024-11-04 23:17:16
Message-ID: 3ed0759d-c332-4f96-a147-499a694e9204@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This query:

SELECT NTH_VALUE(id, 5000000) OVER (ORDER BY created_at, id ASC) FROM table

in a table where SELECT COUNT(*) returns a value a few thousand over 5 million, where id is the primary key, returns null.

The inclusion of the primary key should make the order by a total order. So there should be a 5 millionth row.

How can this happen?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2024-11-04 23:36:17 Re: nth_value out of more than n values returns null
Previous Message Peter J. Holzer 2024-11-04 20:45:54 Re: Used memory calculation in containers - docker stats and file cache