Repository: apache/datafusion-sqlparser-rs (Rust)

Issue:
No support for `ANY` and `ALL` use in `WHERE`
Seems like the parser only supports the use of `ANY` and `ALL` in `SELECT`, not `WHERE`.
This form seems to work:
```
SELECT ALL column_name(s)
FROM table_name
WHERE condition;
```
There's a test for it in `tests/sqlparser_common.rs line: 1539`
This does not supported:
```
SELECT column_name(s)
FROM table_name
WHERE column_name operator ALL
  (SELECT column_name
  FROM table_name
  WHERE condition); 
```
I'm not sure why this is the case. Please let me know if this is intentional. If not I can create a PR. 



Discussion: The defining factor might actually be the use of a subquery after `ALL` of `ANY`.
I think I have a good handle on the issue, can I submit a PR that adds or changes elements to `enum Expr`?  This may be a breaking change. 
Hi @SeanTroyUWO  -- a PR would be most helpful

I am not totally sure what `ALL` and `ANY` mean in SQL, but here is one for adding something similar with `UNION ALL`: https://github.com/sqlparser-rs/sqlparser-rs/pull/915
> Hi @SeanTroyUWO -- a PR would be most helpful
> 
> I am not totally sure what `ALL` and `ANY` mean in SQL, but here is one for adding something similar with `UNION ALL`: #915

Okay finally getting around to this. The issue is I might break code that depends on the current implementation of `ALL` and `ANY`. Is that okay? 



Fix (patch):
diff --git a/src/ast/mod.rs b/src/ast/mod.rs
index a241f9509..41d66166d 100644
--- a/src/ast/mod.rs
+++ b/src/ast/mod.rs
@@ -419,10 +419,18 @@ pub enum Expr {
         pattern: Box<Expr>,
         escape_char: Option<char>,
     },
-    /// Any operation e.g. `1 ANY (1)` or `foo > ANY(bar)`, It will be wrapped in the right side of BinaryExpr
-    AnyOp(Box<Expr>),
-    /// ALL operation e.g. `1 ALL (1)` or `foo > ALL(bar)`, It will be wrapped in the right side of BinaryExpr
-    AllOp(Box<Expr>),
+    /// Any operation e.g. `foo > ANY(bar)`, comparison operator is one of [=, >, <, =>, =<, !=]
+    AnyOp {
+        left: Box<Expr>,
+        compare_op: BinaryOperator,
+        right: Box<Expr>,
+    },
+    /// ALL operation e.g. `foo > ALL(bar)`, comparison operator is one of [=, >, <, =>, =<, !=]
+    AllOp {
+        left: Box<Expr>,
+        compare_op: BinaryOperator,
+        right: Box<Expr>,
+    },
     /// Unary operation e.g. `NOT foo`
     UnaryOp { op: UnaryOperator, expr: Box<Expr> },
     /// CAST an expression to a different data type e.g. `CAST(foo AS VARCHAR(123))`
@@ -724,8 +732,16 @@ impl fmt::Display for Expr {
                     pattern
                 ),
             },
-            Expr::AnyOp(expr) => write!(f, "ANY({expr})"),
-            Expr::AllOp(expr) => write!(f, "ALL({expr})"),
+            Expr::AnyOp {
+                left,
+                compare_op,
+                right,
+            } => write!(f, "{left} {compare_op} ANY({right})"),
+            Expr::AllOp {
+                left,
+                compare_op,
+                right,
+            } => write!(f, "{left} {compare_op} ALL({right})"),
             Expr::UnaryOp { op, expr } => {
                 if op == &UnaryOperator::PGPostfixFactorial {
                     write!(f, "{expr}{op}")
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 846215249..22a3d2c96 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -1773,16 +1773,32 @@ impl<'a> Parser<'a> {
                 let right = self.parse_subexpr(precedence)?;
                 self.expect_token(&Token::RParen)?;
 
-                let right = match keyword {
-                    Keyword::ALL => Box::new(Expr::AllOp(Box::new(right))),
-                    Keyword::ANY => Box::new(Expr::AnyOp(Box::new(right))),
-                    _ => unreachable!(),
+                if !matches!(
+                    op,
+                    BinaryOperator::Gt
+                        | BinaryOperator::Lt
+                        | BinaryOperator::GtEq
+                        | BinaryOperator::LtEq
+                        | BinaryOperator::Eq
+                        | BinaryOperator::NotEq
+                ) {
+                    return parser_err!(format!(
+                        "Expected one of [=, >, <, =>, =<, !=] as comparison operator, found: {op}"
+                    ));
                 };
 
-                Ok(Expr::BinaryOp {
-                    left: Box::new(expr),
-                    op,
-                    right,
+                Ok(match keyword {
+                    Keyword::ALL => Expr::AllOp {
+                        left: Box::new(expr),
+                        compare_op: op,
+                        right: Box::new(right),
+                    },
+                    Keyword::ANY => Expr::AnyOp {
+                        left: Box::new(expr),
+                        compare_op: op,
+                        right: Box::new(right),
+                    },
+                    _ => unreachable!(),
                 })
             } else {
                 Ok(Expr::BinaryOp {