mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-12 06:52:02 +00:00
Support nested expressions in BETWEEN
`BETWEEN <thing> AND <thing>` allows <thing> to be any expr that doesn't contain boolean operators. (Allowing boolean operators would wreak havoc, because of the repurposing of AND as both a boolean operation and part of the syntax of BETWEEN.)
This commit is contained in:
parent
4f944dd4aa
commit
ba21ce9d37
2 changed files with 54 additions and 2 deletions
|
@ -478,9 +478,12 @@ impl Parser {
|
|||
|
||||
/// Parses `BETWEEN <low> AND <high>`, assuming the `BETWEEN` keyword was already consumed
|
||||
pub fn parse_between(&mut self, expr: ASTNode, negated: bool) -> Result<ASTNode, ParserError> {
|
||||
let low = self.parse_prefix()?;
|
||||
// Stop parsing subexpressions for <low> and <high> on tokens with
|
||||
// precedence lower than that of `BETWEEN`, such as `AND`, `IS`, etc.
|
||||
let prec = self.get_precedence(&Token::make_keyword("BETWEEN"))?;
|
||||
let low = self.parse_subexpr(prec)?;
|
||||
self.expect_keyword("AND")?;
|
||||
let high = self.parse_prefix()?;
|
||||
let high = self.parse_subexpr(prec)?;
|
||||
Ok(ASTNode::SQLBetween {
|
||||
expr: Box::new(expr),
|
||||
negated,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue