agora inbox for pgsql-bugs@postgresql.org
help / color / mirror / Atom feedFrom: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: theshallow27@gmail.com
Subject: BUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame
Date: Tue, 29 Sep 2026 19:16:36 +0000
Message-ID: <19731-bf41225d46718e0d@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 19731
Logged by: Shallow
Email address: theshallow27@gmail.com
PostgreSQL version: 18.6
Operating system: Linux
Description:
Summary
When a `ROWS` frame does not include the current row, PostgreSQL can make
`first_value` return a peer excluded from the frame. In this reproducer, the
first row's frame contains only `1` after `EXCLUDE TIES`, and `array_agg`
confirms that frame, but `first_value` returns `0`.
## Reproducer
```sql
WITH t(x) AS (
VALUES (0), (0), (1)
)
SELECT x,
first_value(x) OVER w AS first_in_frame,
array_agg(x) OVER w AS frame_values
FROM t
WINDOW w AS (
ORDER BY x
ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
EXCLUDE TIES
);
```
The SQL window frame is nonempty, so `first_value` should return its first
value. `EXCLUDE TIES` removes peers of the current row but retains non-peer
rows; it must not cause an excluded peer to be returned as though it were
still in the frame.
The related `last_value` case also fails for a frame ending before the
current row. The local triage identifies `WinGetFuncInFrame` in
`src/backend/executor/nodeWindowAgg.c` as the common path: its
current-position fallback appears to assume the current row is in the frame.
Message-ID: <19731-bf41225d46718e0d@postgresql.org>
Permalink: ../19731-bf41225d46718e0d@postgresql.org/
Also on: postgresql.org/message-id/19731-bf41225d46718e0d@postgresql.org
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-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, theshallow27@gmail.com
Subject: Re: BUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame
In-Reply-To: <19731-bf41225d46718e0d@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox