pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame
2+ messages / 2 participants
[nested] [flat]
* BUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame
@ 2026-09-29 19:16 PG Bug reporting form <noreply@postgresql.org>
2026-10-05 02:35 ` Re: BUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame shihao zhong <zhong950419@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: PG Bug reporting form @ 2026-09-29 19:16 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: theshallow27@gmail.com
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame
2026-09-29 19:16 BUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame PG Bug reporting form <noreply@postgresql.org>
@ 2026-10-05 02:35 ` shihao zhong <zhong950419@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: shihao zhong @ 2026-10-05 02:35 UTC (permalink / raw)
To: theshallow27@gmail.com; pgsql-bugs@lists.postgresql.org
Hi,
This is the same bug as BUG #19732. That thread has a patch.
https://postgr.es/m/19732-d4eed889e3021ef8@postgresql.org
Thanks,
shihao zhong
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-10-05 02:35 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29 19:16 BUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame PG Bug reporting form <noreply@postgresql.org>
2026-10-05 02:35 ` shihao zhong <zhong950419@gmail.com>
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