zvonimir-dd commented on code in PR #2701:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/2701#discussion_r4429013709


##########
src/dialect/mysql.rs:
##########
@@ -211,10 +211,11 @@ impl Dialect for MySqlDialect {
         true
     }
 
-    /// `&&` binds like `AND`.
+    /// `&&` binds like `AND`, and `^` binds tighter than `*`, `/`, `DIV`, 
`%`, `MOD`.
     /// See: <https://dev.mysql.com/doc/refman/8.4/en/operator-precedence.html>
     fn get_next_precedence(&self, parser: &Parser) -> Option<Result<u8, 
ParserError>> {
         match parser.peek_token_ref().token {
+            Token::Caret => Some(Ok(self.prec_value(Precedence::MulDivModOp) + 
1)),

Review Comment:
   This also puts `^` above the operand precedence of unary `-`/`+` 
(`parse_prefix` parses their operand at `MulDivModOp`) and of `~` (parsed at 
`PlusMinus`), so those operators now take the whole XOR as their operand:
   
   | SQL | main | this PR | MySQL |
   |---|---|---|---|
   | `-2 ^ 3` | `(-2) ^ 3` | `-(2 ^ 3)` | `(-2) ^ 3` |
   | `~2 ^ 3` | `(~2) ^ 3` | `~(2 ^ 3)` | `(~2) ^ 3` |
   
   In MySQL's table, unary `-` and `~` sit one row above `^`. The `-` case 
changes the result: `(-2) ^ 3` is `18446744073709551613`, `-(2 ^ 3)` is `-1`. 
The `~` case happens to be algebraically equivalent, but the tree still doesn't 
match. Both forms display the same way, so `verified_expr` won't catch this. 
(`~2 * 3` already has this problem on main, so that part is pre-existing.)
   
   One way to fix it: make the operand precedence of prefix `-`/`+`/`~` 
dialect-controlled (e.g. a new `Precedence` variant that defaults to today's 
values), and have MySQL put it above `^`. Either way, could you add `-2 ^ 3` 
and `~2 ^ 3` to `parse_caret_precedence`?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to