@@ -4224,8 +4224,10 @@ impl<'a> Parser<'a> {
42244224 })
42254225 }
42264226
4227+ // Parser is either looking at a : or a bracket expression.
42274228 fn parse_json_path(&mut self) -> Result<JsonPath, ParserError> {
42284229 let mut path = Vec::new();
4230+ let mut has_colon = false;
42294231 loop {
42304232 match self.next_token().token {
42314233 Token::Colon if path.is_empty() && self.peek_token_ref() == &Token::LBracket => {
@@ -4235,16 +4237,19 @@ impl<'a> Parser<'a> {
42354237 path.push(JsonPathElem::ColonBracket { key });
42364238 }
42374239 Token::Colon if path.is_empty() => {
4238- path.push(self.parse_json_path_object_key()?);
4240+ has_colon = true;
4241+ if *self.peek_token_ref() == Token::LBracket {
4242+ path.push(self.parse_json_path_bracket_element()?);
4243+ } else {
4244+ path.push(self.parse_json_path_object_key()?);
4245+ }
42394246 }
42404247 Token::Period if !path.is_empty() => {
42414248 path.push(self.parse_json_path_object_key()?);
42424249 }
42434250 Token::LBracket => {
4244- let key = self.parse_wildcard_expr()?;
4245- self.expect_token(&Token::RBracket)?;
4246-
4247- path.push(JsonPathElem::Bracket { key });
4251+ self.prev_token();
4252+ path.push(self.parse_json_path_bracket_element()?);
42484253 }
42494254 _ => {
42504255 self.prev_token();
@@ -4254,7 +4259,23 @@ impl<'a> Parser<'a> {
42544259 }
42554260
42564261 debug_assert!(!path.is_empty());
4257- Ok(JsonPath { path })
4262+ Ok(JsonPath { has_colon, path })
4263+ }
4264+
4265+ /// Parses a single bracketed element in a JSON path expression, including both brackets.
4266+ fn parse_json_path_bracket_element(&mut self) -> Result<JsonPathElem, ParserError> {
4267+ self.expect_token(&Token::LBracket)?;
4268+ let elem = if *self.peek_token_ref() == Token::Mul
4269+ && self.dialect.supports_semi_structured_array_all_elements()
4270+ {
4271+ self.expect_token(&Token::Mul)?;
4272+ JsonPathElem::AllElements
4273+ } else {
4274+ let key = self.parse_expr()?;
4275+ JsonPathElem::Bracket { key }
4276+ };
4277+ self.expect_token(&Token::RBracket)?;
4278+ Ok(elem)
42584279 }
42594280
42604281 /// Parses the parens following the `[ NOT ] IN` operator.
@@ -4271,25 +4292,34 @@ impl<'a> Parser<'a> {
42714292 negated,
42724293 });
42734294 }
4274- self.expect_token(&Token::LParen)?;
4275- let in_op = match self.maybe_parse(|p| p.parse_query())? {
4276- Some(subquery) => Expr::InSubquery {
4277- expr: Box::new(expr),
4278- subquery,
4279- negated,
4280- },
4281- None => Expr::InList {
4282- expr: Box::new(expr),
4283- list: if self.dialect.supports_in_empty_list() {
4284- self.parse_comma_separated0(Parser::parse_expr, Token::RParen)?
4285- } else {
4286- self.parse_comma_separated(Parser::parse_expr)?
4295+ if self.consume_token(&Token::LParen) {
4296+ let in_op = match self.maybe_parse(|p| p.parse_query())? {
4297+ Some(subquery) => Expr::InSubquery {
4298+ expr: Box::new(expr),
4299+ subquery,
4300+ negated,
42874301 },
4302+ None => Expr::InList {
4303+ expr: Box::new(expr),
4304+ list: if self.dialect.supports_in_empty_list() {
4305+ self.parse_comma_separated0(Parser::parse_expr, Token::RParen)?
4306+ } else {
4307+ self.parse_comma_separated(Parser::parse_expr)?
4308+ },
4309+ negated,
4310+ },
4311+ };
4312+ self.expect_token(&Token::RParen)?;
4313+ Ok(in_op)
4314+ } else {
4315+ // parse an expr
4316+ let in_expr = self.parse_expr()?;
4317+ Ok(Expr::InExpr {
4318+ expr: Box::new(expr),
4319+ in_expr: Box::new(in_expr),
42884320 negated,
4289- },
4290- };
4291- self.expect_token(&Token::RParen)?;
4292- Ok(in_op)
4321+ })
4322+ }
42934323 }
42944324
42954325 /// Parses `BETWEEN <low> AND <high>`, assuming the `BETWEEN` keyword was already consumed.
@@ -15586,7 +15616,8 @@ impl<'a> Parser<'a> {
1558615616 | TableFactor::Unpivot { alias, .. }
1558715617 | TableFactor::MatchRecognize { alias, .. }
1558815618 | TableFactor::SemanticView { alias, .. }
15589- | TableFactor::NestedJoin { alias, .. } => {
15619+ | TableFactor::NestedJoin { alias, .. }
15620+ | TableFactor::PassThroughQuery { alias, .. } => {
1559015621 // but not `FROM (mytable AS alias1) AS alias2`.
1559115622 if let Some(inner_alias) = alias {
1559215623 return Err(ParserError::ParserError(format!(
0 commit comments