mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-03 12:47:21 +00:00
adding support for scale in CEIL and FLOOR functions (#1377)
This commit is contained in:
parent
b072ce2589
commit
c2f46ae07b
3 changed files with 113 additions and 19 deletions
|
@ -1708,12 +1708,22 @@ impl<'a> Parser<'a> {
|
|||
self.expect_token(&Token::LParen)?;
|
||||
let expr = self.parse_expr()?;
|
||||
// Parse `CEIL/FLOOR(expr)`
|
||||
let mut field = DateTimeField::NoDateTime;
|
||||
let keyword_to = self.parse_keyword(Keyword::TO);
|
||||
if keyword_to {
|
||||
let field = if self.parse_keyword(Keyword::TO) {
|
||||
// Parse `CEIL/FLOOR(expr TO DateTimeField)`
|
||||
field = self.parse_date_time_field()?;
|
||||
}
|
||||
CeilFloorKind::DateTimeField(self.parse_date_time_field()?)
|
||||
} else if self.consume_token(&Token::Comma) {
|
||||
// Parse `CEIL/FLOOR(expr, scale)`
|
||||
match self.parse_value()? {
|
||||
Value::Number(n, s) => CeilFloorKind::Scale(Value::Number(n, s)),
|
||||
_ => {
|
||||
return Err(ParserError::ParserError(
|
||||
"Scale field can only be of number type".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CeilFloorKind::DateTimeField(DateTimeField::NoDateTime)
|
||||
};
|
||||
self.expect_token(&Token::RParen)?;
|
||||
if is_ceil {
|
||||
Ok(Expr::Ceil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue