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:
Nikhil Benesch 2019-05-24 14:04:42 -04:00
parent 4f944dd4aa
commit ba21ce9d37
No known key found for this signature in database
GPG key ID: F7386C5DEADABA7F
2 changed files with 54 additions and 2 deletions

View file

@ -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,