mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-11 22:42:02 +00:00
Fix precedence of unary NOT
get_next_precedence deals with left-binding power, not right binding power. Therefore, when it encounters a standalone NOT operator (i.e., a "NOT" token that is not followed by "BETWEEN", "LIKE", or "IN"), it should return 0, because unary NOT is not an infix operator, it's a prefix operator, and therefore it has no left-binding power.
This commit is contained in:
parent
1f87083906
commit
525f4d7501
2 changed files with 4 additions and 3 deletions
|
@ -580,11 +580,12 @@ impl Parser {
|
|||
// The precedence of NOT varies depending on keyword that
|
||||
// follows it. If it is followed by IN, BETWEEN, or LIKE,
|
||||
// it takes on the precedence of those tokens. Otherwise it
|
||||
// takes on UNARY_NOT_PREC.
|
||||
// is not an infix operator, and therefore has zero
|
||||
// precedence.
|
||||
Some(Token::SQLWord(k)) if k.keyword == "IN" => Ok(Self::BETWEEN_PREC),
|
||||
Some(Token::SQLWord(k)) if k.keyword == "BETWEEN" => Ok(Self::BETWEEN_PREC),
|
||||
Some(Token::SQLWord(k)) if k.keyword == "LIKE" => Ok(Self::BETWEEN_PREC),
|
||||
_ => Ok(Self::UNARY_NOT_PREC),
|
||||
_ => Ok(0),
|
||||
},
|
||||
Token::SQLWord(k) if k.keyword == "IS" => Ok(17),
|
||||
Token::SQLWord(k) if k.keyword == "IN" => Ok(Self::BETWEEN_PREC),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue