Skip to content

parser: reject IN without a parenthesised list/subquery (was silently dropped)#48

Merged
chiradip merged 1 commit into
mainfrom
fix-in-without-parens
Jul 27, 2026
Merged

parser: reject IN without a parenthesised list/subquery (was silently dropped)#48
chiradip merged 1 commit into
mainfrom
fix-in-without-parens

Conversation

@chiradip

@chiradip chiradip commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What

WHERE a IN 5 (an IN not followed by parentheses) silently dropped the predicate: the parser left in_operand null, hit the "neither list nor subquery" fallback, and continued without building an InExpr, so the predicate degraded to its bare left operand a. The WHERE effectively vanished — a silent wrong result that would return all rows.

How

IN must be followed by a parenthesised value list or subquery. Error when it isn't, instead of dropping it. The valid forms are untouched.

Before / after

WHERE a IN 5 — before: WhereClause → ColumnRef('a') (the IN 5 gone, 1 trailing token); after: PARSE ERROR: expected '(' with a value list or subquery after IN.

Tests

test_parser_expr_hardening: a IN 5 / a NOT IN 5 rejected; a IN (1,2,3), a IN (SELECT …), a NOT IN (1,2) still parse to InExpr (regression guard). Full suite 37/37 green.

Part of the parser-layer robustness pass (CASE #46 and IS DISTINCT FROM #47 merged; the set-operation drops follow).

… dropped)

`IN` must be followed by a parenthesised value list or subquery. When it was
not - e.g. `WHERE a IN 5` - the parser left `in_operand` null, hit the
"neither list nor subquery" fallback, and `continue`d without building an
InExpr: the IN was swallowed and the predicate degraded to its bare left
operand `a`. That is a silent wrong result - the filter effectively vanished
and the query would return all rows.

Error out when IN is not followed by `(`, instead of dropping it. The valid
parenthesised list and subquery forms (and NOT IN) are unchanged.

Tests (test_parser_expr_hardening): `a IN 5` / `a NOT IN 5` are rejected;
`a IN (1,2,3)`, `a IN (SELECT ...)`, and `a NOT IN (1,2)` still parse to InExpr.
Full suite 37/37 green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FyKDAbMWGwiZq4iJx3imsg
@chiradip
chiradip merged commit da33a91 into main Jul 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants