#25699·duckdb

Equivalent argument `ORDER BY` clauses make `LEAD` return different results

Author: Yibo-DongCreated Sep 14, 2026Updated Sep 17, 2026
Labelsreproduced

What happens?

Two LEAD calls with semantically equivalent argument orderings return different results when the same frame clause is present: one returns NULL for the first row while the other returns a.

To Reproduce

Code

sql
SET threads=1;

WITH t(id, x) AS (
  VALUES (1, 'b'), (2, 'a')
)
SELECT
  id,
  x,
  LEAD(x ORDER BY x DESC, id DESC) OVER (
    ORDER BY x DESC, id ASC
    ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
  ) AS actual,
  LEAD(x ORDER BY x DESC, id ASC) OVER (
    ORDER BY x DESC, id ASC
    ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
  ) AS equivalent_control
FROM t
ORDER BY id;

Expected

id x actual equivalent_control
1 b a a
2 a NULL NULL

Actual

id x actual equivalent_control
1 b NULL a
2 a NULL NULL

OS:

macOS 15.7.4, arm64

DuckDB Version:

current main (8bc48eb3fe36f13b5e57e5e136c3ba85cc7d74d4, v2.1.0-dev84598)

DuckDB Client:

CLI

Hardware:

No response

Full Name:

Yibo Dong

Affiliation:

National University of Singapore

Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?

  • Yes, I have

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant data sets for reproducing the issue?

Yes