@@ -28,7 +28,7 @@ database engine.
2828The following SQL features are ** rejected at parse time** with ` ValueError ` :
2929
3030- ` JOIN ` (any variant: INNER, LEFT, RIGHT, CROSS, NATURAL)
31- - Subqueries (scalar, correlated, or in FROM)
31+ - Subqueries except ` WHERE col IN (SELECT single_col FROM table [WHERE ...]) `
3232- Common Table Expressions (CTEs / ` WITH ` )
3333- ` UNION ` / ` INTERSECT ` / ` EXCEPT `
3434- Window functions (` OVER ` , ` PARTITION BY ` )
@@ -299,6 +299,7 @@ DELETE FROM table [WHERE conditions]
299299| ` IS NULL ` | ` WHERE name IS NULL ` | NULL check |
300300| ` IS NOT NULL ` | ` WHERE name IS NOT NULL ` | Non-NULL check |
301301| ` IN ` | ` WHERE name IN ('Alice', 'Bob') ` | Set membership |
302+ | ` IN ` subquery | ` WHERE id IN (SELECT id FROM admins WHERE role = 'admin') ` | Set membership from subquery |
302303| ` BETWEEN ` | ` WHERE score BETWEEN 70 AND 90 ` | Inclusive range |
303304| ` LIKE ` | ` WHERE name LIKE 'A%' ` | Pattern matching |
304305
@@ -316,6 +317,9 @@ Example: `WHERE name LIKE 'A%'` matches "Alice", "Ann", "A".
316317- Values must be parenthesized: ` IN (1, 2, 3) ` or ` IN ('a', 'b') `
317318- Empty IN list raises ` ValueError `
318319- Supports placeholder binding: ` IN (?, ?, ?) `
320+ - Supports single-column subqueries: ` IN (SELECT id FROM admins) `
321+ - Subquery form supports optional inner WHERE: ` IN (SELECT id FROM admins WHERE role = 'admin') `
322+ - Subquery limits: single-column SELECT only, non-correlated only, no scalar subqueries, no FROM-subqueries
319323
320324#### 7.2.3 BETWEEN Clause
321325
@@ -334,7 +338,7 @@ Example: `WHERE name LIKE 'A%'` matches "Alice", "Ann", "A".
334338 - ` a OR b AND c ` = ` a OR (b AND c) `
335339- ` NOT ` operator is ** not supported** .
336340- Parenthesized expressions in WHERE (e.g., ` WHERE (x = 1) ` ) are ** not supported**
337- and raise ` ValueError ` . Exception : parentheses in ` IN (...) ` are allowed.
341+ and raise ` ValueError ` . Exceptions : parentheses in ` IN (...) ` literal lists and ` IN (SELECT ...)` are allowed.
338342
339343### 7.4 Type Coercion
340344
@@ -454,9 +458,12 @@ where_expr = condition { ("AND" | "OR") condition } ;
454458condition = column operator value
455459 | column "IS" [ "NOT" ] "NULL"
456460 | column "IN" "(" value_list ")"
461+ | column "IN" "(" subquery_select ")"
457462 | column "BETWEEN" value "AND" value
458463 | column "LIKE" pattern ;
459464
465+ subquery_select = "SELECT" column "FROM" table [ "WHERE" where_expr ] ;
466+
460467operator = "=" | "==" | "!=" | "<>" | ">" | ">=" | "<" | "<=" ;
461468direction = "ASC" | "DESC" ;
462469value = string | number | "NULL" | "?" ;
0 commit comments