Repository navigation
SQLite: Support IN with a table name or table-valued function
#2680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1560d63
617b92c
11eb238
80ba734
2c17821
8a95727
0433383
7c74aa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| SELECT 1 IN view, 1 IN offset, 1 IN key, 1 IN abort FROM t; | ||
| SELECT 1 IN "from" FROM t | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,6 +193,10 @@ impl Dialect for GenericDialect { | |
| true | ||
| } | ||
|
|
||
| fn supports_in_table_expression(&self) -> bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| true | ||
| } | ||
|
|
||
| fn supports_comment_on(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4531,6 +4531,19 @@ impl<'a> Parser<'a> { | |
| let array_expr = self.parse_expr()?; | ||
| self.expect_token(&Token::RParen)?; | ||
| InTarget::Unnest(Box::new(array_expr)) | ||
| } else if !global | ||
| && self.dialect.supports_in_table_expression() | ||
| && self.next_word_is_table_name() | ||
| { | ||
| let name = self.parse_object_name(false)?; | ||
| let args = if self.consume_token(&Token::LParen) { | ||
| let args = self.parse_comma_separated0(Self::parse_function_args, Token::RParen)?; | ||
| self.expect_token(&Token::RParen)?; | ||
| Some(args) | ||
| } else { | ||
| None | ||
| }; | ||
| InTarget::Table { name, args } | ||
| } else if self.dialect.supports_in_unparenthesized_expr() | ||
| && self.peek_token_ref().token != Token::LParen | ||
| { | ||
|
|
@@ -4548,6 +4561,20 @@ impl<'a> Parser<'a> { | |
| }) | ||
| } | ||
|
|
||
| /// 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 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be next_word_is_table_factor? |
||
| let Token::Word(word) = &self.peek_token_ref().token else { | ||
| return false; | ||
| }; | ||
| let keyword = word.keyword; | ||
| self.advance_token(); | ||
| let is_name = self.dialect.is_table_factor(&keyword, self); | ||
| self.prev_token(); | ||
| is_name | ||
| } | ||
|
|
||
| /// Parses the parenthesized subquery or value list of an `IN` predicate. | ||
| fn parse_in_parenthesized_target(&mut self) -> Result<InTarget, ParserError> { | ||
| self.expect_token(&Token::LParen)?; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫰