-
-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Labels
Description
Description
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).
Skipped tests: https://github.com/dolthub/doltgresql/blob/main/testing/go/values_statement_test.go#L189-L224
Repro
1. Arithmetic in subquery over VALUES
-- Returns original values (1, 2.5, 3) instead of doubled values (2, 5.0, 6)
SELECT * FROM (SELECT n * 2 AS 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 2
SELECT * FROM (SELECT * FROM (VALUES(1),(2.5),(3),(4.5)) v(n) LIMIT 2) 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.
Reactions are currently unavailable