pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Guyren Howe <guyren@gmail.com>
To: PG-General Mailing List <pgsql-general@postgresql.org>
Subject: nth_value out of more than n values returns null
Date: Mon, 4 Nov 2024 15:17:16 -0800
Message-ID: <3ed0759d-c332-4f96-a147-499a694e9204@Spark> (raw)

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?

view thread (8+ messages)  latest in thread

Message-ID: <3ed0759d-c332-4f96-a147-499a694e9204@Spark>
Permalink:  ../3ed0759d-c332-4f96-a147-499a694e9204@Spark/
Also on:    postgresql.org/message-id/3ed0759d-c332-4f96-a147-499a694e9204@Spark

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-general@postgresql.org
  Cc: guyren@gmail.com
  Subject: Re: nth_value out of more than n values returns null
  In-Reply-To: <3ed0759d-c332-4f96-a147-499a694e9204@Spark>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox