mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-20 14:10:15 +00:00
feat: Convert IS TRUE|FALSE to expression (#499)
This commit is contained in:
parent
a6d7a35dac
commit
4070f3ec6e
3 changed files with 27 additions and 20 deletions
|
@ -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(),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue