Re: BUG #19732: first_value/last_value/nth_value return NULL with EXCLUDE TIES when the current row is outside its f

From: QQ Mail <781408517(at)qq(dot)com>
To: pl0h0yp1(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19732: first_value/last_value/nth_value return NULL with EXCLUDE TIES when the current row is outside its f
Date: 2026-10-12 08:14:16
Message-ID: tencent_A9B1975C151B0BE041E920C3FC09F0B3D907@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Andrey,

With AI assistance, I tested v3 against 9e7d152488f197e96f171f0714459c227c3f7693 on Linux x86_64 with GCC 14.2.0 and assertions enabled. All 239 core regression tests passed via make installcheck.

One regression suggestion: could we also include nth_value with n greater than 1? This small case returns the wrong non-NULL value before the patch:

SELECT k, nth_value(k, 2) OVER w,
(array_agg(k) OVER w)[2] AS expected
FROM (VALUES (0), (0), (1), (2)) AS t(k)
WINDOW w AS (
ORDER BY k
ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
EXCLUDE TIES
);

For the first row, the unpatched code returns 1 instead of 2. With v3, both columns return 2.

I also checked first_value, last_value and nth_value against array_agg across a bounded matrix of ROWS/RANGE/GROUPS frames and exclusion options, including NULL payloads, multiple partitions, descending ordering, and varying or NULL nth_value offsets. All 61,920 row comparisons matched with v3. The unpatched build showed mismatches and mark-position errors only in the ROWS/EXCLUDE TIES cases.

I did not find a correctness issue in these checks.

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Matthias van de Meent 2026-10-12 10:57:37 Re: BUG #19519: REPACK can fail due to missing chunk for toast value
Previous Message PG Bug reporting form 2026-10-12 07:53:16 BUG #19754: pg_restore + zlib 1.3.2: intact files rejected, truncated files accepted