Merge pull request #90 from benesch/exists

Support EXISTS subqueries
This commit is contained in:
Nikhil Benesch 2019-06-03 11:29:04 -04:00 committed by GitHub
commit 7aff70772b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 0 deletions

View file

@ -191,6 +191,7 @@ impl Parser {
}
"CASE" => self.parse_case_expression(),
"CAST" => self.parse_cast_expression(),
"EXISTS" => self.parse_exists_expression(),
"NOT" => Ok(ASTNode::SQLUnary {
operator: SQLOperator::Not,
expr: Box::new(self.parse_subexpr(Self::UNARY_NOT_PREC)?),
@ -404,6 +405,14 @@ impl Parser {
})
}
/// Parse a SQL EXISTS expression e.g. `WHERE EXISTS(SELECT ...)`.
pub fn parse_exists_expression(&mut self) -> Result<ASTNode, ParserError> {
self.expect_token(&Token::LParen)?;
let exists_node = ASTNode::SQLExists(Box::new(self.parse_query()?));
self.expect_token(&Token::RParen)?;
Ok(exists_node)
}
/// Parse an operator following an expression
pub fn parse_infix(&mut self, expr: ASTNode, precedence: u8) -> Result<ASTNode, ParserError> {
debug!("parsing infix");