feat: Convert IS TRUE|FALSE to expression (#499)

This commit is contained in:
Dmitry Patsura 2022-05-24 16:26:50 +03:00 committed by GitHub
parent a6d7a35dac
commit 4070f3ec6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 20 deletions

View file

@ -1155,6 +1155,10 @@ impl<'a> Parser<'a> {
Ok(Expr::IsNull(Box::new(expr)))
} else if self.parse_keywords(&[Keyword::NOT, Keyword::NULL]) {
Ok(Expr::IsNotNull(Box::new(expr)))
} else if self.parse_keywords(&[Keyword::TRUE]) {
Ok(Expr::IsTrue(Box::new(expr)))
} else if self.parse_keywords(&[Keyword::FALSE]) {
Ok(Expr::IsFalse(Box::new(expr)))
} else if self.parse_keywords(&[Keyword::DISTINCT, Keyword::FROM]) {
let expr2 = self.parse_expr()?;
Ok(Expr::IsDistinctFrom(Box::new(expr), Box::new(expr2)))
@ -1162,21 +1166,9 @@ impl<'a> Parser<'a> {
{
let expr2 = self.parse_expr()?;
Ok(Expr::IsNotDistinctFrom(Box::new(expr), Box::new(expr2)))
} else if let Some(right) =
self.parse_one_of_keywords(&[Keyword::TRUE, Keyword::FALSE])
{
let mut val = Value::Boolean(true);
if right == Keyword::FALSE {
val = Value::Boolean(false);
}
Ok(Expr::BinaryOp {
left: Box::new(expr),
op: BinaryOperator::Eq,
right: Box::new(Expr::Value(val)),
})
} else {
self.expected(
"[NOT] NULL or [NOT] DISTINCT FROM TRUE FALSE after IS",
"[NOT] NULL or TRUE|FALSE or [NOT] DISTINCT FROM after IS",
self.peek_token(),
)
}