You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: VALUES inside subquery ignores projections, LIMIT, and ORDER BY #2373
When a VALUES clause is used as a data source inside a subquery, operations applied in the outer SELECT of that subquery (arithmetic projections, LIMIT, ORDER BY) are silently ignored. The subquery behaves as if it were just SELECT * FROM (VALUES ...) v(n), discarding any transformations or constraints.
This affects three distinct operations:
Arithmetic projections on VALUES columns are not applied
LIMIT inside a subquery over VALUES is ignored (all rows returned)
ORDER BY inside a subquery over VALUES is ignored (insertion order preserved)
All three work correctly when applied directly to a VALUES clause (not wrapped in a subquery).
-- Returns original values (1, 2.5, 3) instead of doubled values (2, 5.0, 6)SELECT*FROM (SELECT n *2AS doubled FROM (VALUES(1),(2.5),(3)) v(n)) sub;
Expected:
doubled
2
5.0
6
Actual:
doubled
1
2.5
3
The n * 2 expression is completely ignored.
2. LIMIT inside subquery over VALUES
-- Returns all 4 rows instead of only 2SELECT*FROM (SELECT*FROM (VALUES(1),(2.5),(3),(4.5)) v(n) LIMIT2) sub;
Expected:
n
1
2.5
Actual:
n
1
2.5
3
4.5
The LIMIT 2 is ignored.
3. ORDER BY inside subquery over VALUES
-- Returns rows in insertion order (3, 1.5, 2) instead of sorted order (1.5, 2, 3)SELECT*FROM (SELECT*FROM (VALUES(3),(1.5),(2)) v(n) ORDER BY n) sub;
Expected:
n
1.5
2
3
Actual:
n
3
1.5
2
The ORDER BY n is ignored.
Notes
Operations applied directly to VALUES (not inside a subquery) work correctly. For example, SELECT * FROM (VALUES(1),(2.5),(3)) v(n) LIMIT 2; returns 2 rows as expected.
The bug only manifests when VALUES is nested inside a subquery that applies additional operations.
Activity
Fix VALUES inside subquery ignoring projections, LIMIT, and ORDER BY
codeaucafe commentedon Feb 28, 2026
fyi I'm working on this if that's fine. Will hope to have PR fix up in few days.
fix: VALUES inside subquery ignoring projections, LIMIT, and ORDER BY
fix(ast,analyzer): prevent VALUES subquery unwrap from dropping clauses
fix(ast,analyzer): prevent VALUES subquery unwrap from dropping clauses
fix(ast,analyzer): prevent VALUES subquery unwrap from dropping clauses
refactor(ast,analyzer): address PR review comments
refactor(ast): fold SelectExprs len check into main if stmt
Merge pull request #2402 from codeaucafe/codeaucafe/2373-fix-subquery…