mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-14 15:59:03 +00:00
Parse SUBSTRING
FROM
syntax in all dialects, reflect change in the AST (#1173)
This commit is contained in:
parent
929c646bba
commit
6b03a259aa
7 changed files with 47 additions and 95 deletions
|
@ -1525,47 +1525,27 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
pub fn parse_substring_expr(&mut self) -> Result<Expr, ParserError> {
|
||||
if self.dialect.supports_substring_from_for_expr() {
|
||||
// PARSE SUBSTRING (EXPR [FROM 1] [FOR 3])
|
||||
self.expect_token(&Token::LParen)?;
|
||||
let expr = self.parse_expr()?;
|
||||
let mut from_expr = None;
|
||||
if self.parse_keyword(Keyword::FROM) || self.consume_token(&Token::Comma) {
|
||||
from_expr = Some(self.parse_expr()?);
|
||||
}
|
||||
|
||||
let mut to_expr = None;
|
||||
if self.parse_keyword(Keyword::FOR) || self.consume_token(&Token::Comma) {
|
||||
to_expr = Some(self.parse_expr()?);
|
||||
}
|
||||
self.expect_token(&Token::RParen)?;
|
||||
|
||||
Ok(Expr::Substring {
|
||||
expr: Box::new(expr),
|
||||
substring_from: from_expr.map(Box::new),
|
||||
substring_for: to_expr.map(Box::new),
|
||||
special: false,
|
||||
})
|
||||
} else {
|
||||
// PARSE SUBSTRING(EXPR, start, length)
|
||||
self.expect_token(&Token::LParen)?;
|
||||
let expr = self.parse_expr()?;
|
||||
|
||||
self.expect_token(&Token::Comma)?;
|
||||
let from_expr = Some(self.parse_expr()?);
|
||||
|
||||
self.expect_token(&Token::Comma)?;
|
||||
let to_expr = Some(self.parse_expr()?);
|
||||
|
||||
self.expect_token(&Token::RParen)?;
|
||||
|
||||
Ok(Expr::Substring {
|
||||
expr: Box::new(expr),
|
||||
substring_from: from_expr.map(Box::new),
|
||||
substring_for: to_expr.map(Box::new),
|
||||
special: true,
|
||||
})
|
||||
// PARSE SUBSTRING (EXPR [FROM 1] [FOR 3])
|
||||
self.expect_token(&Token::LParen)?;
|
||||
let expr = self.parse_expr()?;
|
||||
let mut from_expr = None;
|
||||
let special = self.consume_token(&Token::Comma);
|
||||
if special || self.parse_keyword(Keyword::FROM) {
|
||||
from_expr = Some(self.parse_expr()?);
|
||||
}
|
||||
|
||||
let mut to_expr = None;
|
||||
if self.parse_keyword(Keyword::FOR) || self.consume_token(&Token::Comma) {
|
||||
to_expr = Some(self.parse_expr()?);
|
||||
}
|
||||
self.expect_token(&Token::RParen)?;
|
||||
|
||||
Ok(Expr::Substring {
|
||||
expr: Box::new(expr),
|
||||
substring_from: from_expr.map(Box::new),
|
||||
substring_for: to_expr.map(Box::new),
|
||||
special,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse_overlay_expr(&mut self) -> Result<Expr, ParserError> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue