adamchainz commented on code in PR #1793:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1793#discussion_r2029486915


##########
src/parser/mod.rs:
##########
@@ -3742,24 +3742,23 @@ impl<'a> Parser<'a> {
             });
         }
         self.expect_token(&Token::LParen)?;
-        let in_op = if self.parse_keyword(Keyword::SELECT) || 
self.parse_keyword(Keyword::WITH) {
-            self.prev_token();
-            Expr::InSubquery {
+        let in_op = match self.try_parse(|p| 
p.parse_query_body(p.dialect.prec_unknown())) {

Review Comment:
   The previous approach peeked for a `SELECT` or `WITH`, but we cannot rely on 
that because there may be more than one parenthesis, as in `IN ((SELECT ...) 
UNION ())`.
   
   The new approach tries to parse a subquery first, then an in list second.



##########
tests/sqlparser_common.rs:
##########
@@ -2224,7 +2224,21 @@ fn parse_in_subquery() {
     assert_eq!(
         Expr::InSubquery {
             expr: Box::new(Expr::Identifier(Ident::new("segment"))),
-            subquery: Box::new(verified_query("SELECT segm FROM bar")),
+            subquery: verified_query("SELECT segm FROM bar").body,
+            negated: false,
+        },
+        select.selection.unwrap()
+    );
+}
+
+#[test]
+fn parse_in_union() {

Review Comment:
   I only added one test - happy to add more if deemed necessary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to