Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xBphZ-00000003PR5-2WPi for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Sep 2026 08:30:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xBphY-000000012xb-1Ws8 for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Sep 2026 08:30:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xBdK6-0000000GIYo-3Ct7 for pgsql-bugs@lists.postgresql.org; Tue, 29 Sep 2026 19:17:06 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xBdK5-00000001v2Y-15KX for pgsql-bugs@lists.postgresql.org; Tue, 29 Sep 2026 19:17:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=kfl2o/o0sDhxbIozIZOT7OBgPo/3OxA8r74QGs77Sog=; b=0ATiJCgPW0Ua/T4ea4ONT2OXxU rrbkNm1xGBEDtu2ZN75RVNV07F7XWpb5B/yNZNiJM5KM9iopLPzSbAeTxUUfGXzX62tMOyUOJ+WYO vrsLMDqIsUw4gx3iC5FbALoM0Xba2gK1YJly+7Y5jKI9LtFPPpa1OuSIhOuYvXlPkGB6xcI97dUWg RvCl4bk9iymQhXxO24sd1BgWqUk/Wzn1gaCkJ3/07Qe7pwQsUV7bSorjfIXgZ6eTOAcqx5OhZBxfS CT7IGcO6CkJg6mBifR7qE0wnlI6Uy6pTM4UznH3N41nYRBzaQ0R1coVQPmiQ9qfPtfYdloBSb4CNA y8IyCTig==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xBdK4-000ZS0-33 for pgsql-bugs@lists.postgresql.org; Tue, 29 Sep 2026 19:17:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xBdK3-0000000GVo1-3fXF for pgsql-bugs@lists.postgresql.org; Tue, 29 Sep 2026 19:17:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19731: `first_value` returns an excluded peer for a nonempty `EXCLUDE TIES` frame To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: theshallow27@gmail.com Reply-To: theshallow27@gmail.com, pgsql-bugs@lists.postgresql.org Date: Tue, 29 Sep 2026 19:16:36 +0000 Message-ID: <19731-bf41225d46718e0d@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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: =20 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.