mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-03 20:50:33 +00:00
Snowflake: support position with normal function call syntax (#1341)
Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
parent
7fdb2ec5d1
commit
c3ba2f33c6
3 changed files with 39 additions and 27 deletions
|
@ -1038,7 +1038,7 @@ impl<'a> Parser<'a> {
|
|||
Keyword::CEIL => self.parse_ceil_floor_expr(true),
|
||||
Keyword::FLOOR => self.parse_ceil_floor_expr(false),
|
||||
Keyword::POSITION if self.peek_token().token == Token::LParen => {
|
||||
self.parse_position_expr()
|
||||
self.parse_position_expr(w.to_ident())
|
||||
}
|
||||
Keyword::SUBSTRING => self.parse_substring_expr(),
|
||||
Keyword::OVERLAY => self.parse_overlay_expr(),
|
||||
|
@ -1707,24 +1707,26 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_position_expr(&mut self) -> Result<Expr, ParserError> {
|
||||
// PARSE SELECT POSITION('@' in field)
|
||||
self.expect_token(&Token::LParen)?;
|
||||
pub fn parse_position_expr(&mut self, ident: Ident) -> Result<Expr, ParserError> {
|
||||
let position_expr = self.maybe_parse(|p| {
|
||||
// PARSE SELECT POSITION('@' in field)
|
||||
p.expect_token(&Token::LParen)?;
|
||||
|
||||
// Parse the subexpr till the IN keyword
|
||||
let expr = self.parse_subexpr(Self::BETWEEN_PREC)?;
|
||||
if self.parse_keyword(Keyword::IN) {
|
||||
let from = self.parse_expr()?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
// Parse the subexpr till the IN keyword
|
||||
let expr = p.parse_subexpr(Self::BETWEEN_PREC)?;
|
||||
p.expect_keyword(Keyword::IN)?;
|
||||
let from = p.parse_expr()?;
|
||||
p.expect_token(&Token::RParen)?;
|
||||
Ok(Expr::Position {
|
||||
expr: Box::new(expr),
|
||||
r#in: Box::new(from),
|
||||
})
|
||||
} else {
|
||||
parser_err!(
|
||||
"Position function must include IN keyword".to_string(),
|
||||
self.peek_token().location
|
||||
)
|
||||
});
|
||||
match position_expr {
|
||||
Some(expr) => Ok(expr),
|
||||
// Snowflake supports `position` as an ordinary function call
|
||||
// without the special `IN` syntax.
|
||||
None => self.parse_function(ObjectName(vec![ident])),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue