Skip to content

SQLite: Support IN with a table name or table-valued function - #2680

Open
LucaCappelletti94 wants to merge 5 commits into
in-expr-refactorfrom
sqlite-in-table
Open

LucaCappelletti94 wants to merge 5 commits into
in-expr-refactorfrom
sqlite-in-table

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Stacked on the IN refactor PR.

In SQLite "the right-hand side of an IN or NOT IN operator can be a table name or table-valued function name in which case the right-hand side is understood to be a subquery of the form (SELECT * FROM name)" (https://www.sqlite.org/lang_expr.html#in_op). SQLite 3.51.1 runs SELECT 1 IN t, SELECT 1 NOT IN t and SELECT 1 IN main.t, but the SQLite dialect failed with Expected: (, found: t.

InTarget gains a Table { name, args } variant, and a new dialect method, supports_in_table_expression, enables it for SQLite and the generic dialect. It does not apply to ClickHouse's GLOBAL IN. Tests round-trip plain, qualified and function forms with and without NOT, check the parsed name and arguments, and check that parenthesized lists and subqueries still parse as before.

@codecov-commenter

codecov-commenter commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.41%. Comparing base (5d8f8d5) to head (82c6b85).

Files with missing lines Patch % Lines
src/parser/mod.rs 84.21% 0 Missing and 3 partials ⚠️
src/ast/mod.rs 66.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@                 Coverage Diff                  @@
##           in-expr-refactor    #2680      +/-   ##
====================================================
+ Coverage             81.33%   81.41%   +0.08%     
====================================================
  Files                    42       42              
  Lines                 33957    34012      +55     
  Branches              33957    34012      +55     
====================================================
+ Hits                  27618    27692      +74     
+ Misses                 2775     2749      -26     
- Partials               3564     3571       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94
LucaCappelletti94 marked this pull request as ready for review October 18, 2026 19:32
Comment thread src/parser/mod.rs Outdated
InTarget::Unnest(Box::new(array_expr))
} else if !global
&& self.dialect.supports_in_table_expression()
&& matches!(self.peek_token_ref().token, Token::Word(_))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any word is taken as the table name, so SELECT 1 IN FROM t parses and round-trips to SELECT 1 IN FROM AS t. Worth the same reserved-keyword check as the table factor position (is_table_factor, cf. #2633).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_table_factor with the shared list would still accept this one, since FROM is not in RESERVED_FOR_TABLE_FACTOR. I ran every keyword of the crate through SQLite 3.51.1 as SELECT 1 IN <kw>, and SQLite refuses 57 of them there, so now SQLiteDialect overrides is_table_factor with those, so SELECT 1 IN FROM t fails again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants