mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 18:57:21 +00:00
Support PostgreSQL array subquery constructor (#566)
This commit is contained in:
parent
61dc3e9bf9
commit
31ba0012f7
5 changed files with 101 additions and 2 deletions
|
@ -449,11 +449,18 @@ impl<'a> Parser<'a> {
|
|||
Keyword::TRIM => self.parse_trim_expr(),
|
||||
Keyword::INTERVAL => self.parse_literal_interval(),
|
||||
Keyword::LISTAGG => self.parse_listagg_expr(),
|
||||
// Treat ARRAY[1,2,3] as an array [1,2,3], otherwise try as function call
|
||||
// Treat ARRAY[1,2,3] as an array [1,2,3], otherwise try as subquery or a function call
|
||||
Keyword::ARRAY if self.peek_token() == Token::LBracket => {
|
||||
self.expect_token(&Token::LBracket)?;
|
||||
self.parse_array_expr(true)
|
||||
}
|
||||
Keyword::ARRAY
|
||||
if self.peek_token() == Token::LParen
|
||||
&& !dialect_of!(self is ClickHouseDialect) =>
|
||||
{
|
||||
self.expect_token(&Token::LParen)?;
|
||||
self.parse_array_subquery()
|
||||
}
|
||||
Keyword::NOT => self.parse_not(),
|
||||
// Here `w` is a word, check if it's a part of a multi-part
|
||||
// identifier, a function call, or a simple identifier:
|
||||
|
@ -927,6 +934,13 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
// Parses an array constructed from a subquery
|
||||
pub fn parse_array_subquery(&mut self) -> Result<Expr, ParserError> {
|
||||
let query = self.parse_query()?;
|
||||
self.expect_token(&Token::RParen)?;
|
||||
Ok(Expr::ArraySubquery(Box::new(query)))
|
||||
}
|
||||
|
||||
/// Parse a SQL LISTAGG expression, e.g. `LISTAGG(...) WITHIN GROUP (ORDER BY ...)`.
|
||||
pub fn parse_listagg_expr(&mut self) -> Result<Expr, ParserError> {
|
||||
self.expect_token(&Token::LParen)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue