Skip to content

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

Open
LucaCappelletti94 wants to merge 8 commits into
mainfrom
sqlite-in-table
Open

LucaCappelletti94 wants to merge 8 commits into
mainfrom
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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.03%. Comparing base (5679f2f) to head (afe93cf).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2680      +/-   ##
==========================================
+ Coverage   81.94%   82.03%   +0.08%     
==========================================
  Files          42       42              
  Lines       34949    35004      +55     
  Branches    34949    35004      +55     
==========================================
+ Hits        28638    28714      +76     
+ Misses       2744     2721      -23     
- Partials     3567     3569       +2     

☔ 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.

Base automatically changed from in-expr-refactor to main October 21, 2026 07:18
@LucaCappelletti94
LucaCappelletti94 force-pushed the sqlite-in-table branch 6 times, most recently from 3910006 to 74938bb Compare October 24, 2026 08:44

@s5dsn-eqee s5dsn-eqee left a comment

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.

LGTM! Left a few non-blocking comments inline.

Comment thread src/parser/mod.rs
/// Returns true if the next token is a word the dialect accepts as a table
/// name. The word is consumed while asking, so `is_table_factor` peeks past
/// it as it does at the trailing comma check.
fn next_word_is_table_name(&mut self) -> bool {

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.

might be next_word_is_table_factor?

Comment thread src/dialect/generic.rs
true
}

fn supports_in_table_expression(&self) -> bool {

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.

GenericDialect now accepts reserved words as an IN table name, because it
keeps the default is_table_factor (which reserves only INTO, LIMIT,
HAVING, WHERE). Inputs that failed with Expected: ( before now parse:

  • SELECT 1 IN NULL -> table named NULL
  • SELECT 1 IN select -> table named select
  • SELECT 1 IN case -> table named case

@@ -0,0 +1,3 @@
SELECT a IN t, a NOT IN t, a IN main.t, a IN f(), a NOT IN f(1, 2), a IN main.f(1) FROM t;

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.

🫰

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.

4 participants