@@ -1123,9 +1123,8 @@ impl<'a> Parser<'a> {
11231123 Keyword::MATCH if dialect_of!(self is MySqlDialect | GenericDialect) => {
11241124 Ok(Some(self.parse_match_against()?))
11251125 }
1126- Keyword::STRUCT if dialect_of!(self is BigQueryDialect | GenericDialect) => {
1127- self.prev_token();
1128- Ok(Some(self.parse_bigquery_struct_literal()?))
1126+ Keyword::STRUCT if self.dialect.supports_struct_literal() => {
1127+ Ok(Some(self.parse_struct_literal()?))
11291128 }
11301129 Keyword::PRIOR if matches!(self.state, ParserState::ConnectBy) => {
11311130 let expr = self.parse_subexpr(self.dialect.prec_value(Precedence::PlusMinus))?;
@@ -2383,22 +2382,28 @@ impl<'a> Parser<'a> {
23832382 }
23842383 }
23852384
2386- /// Bigquery specific: Parse a struct literal
23872385 /// Syntax
23882386 /// ```sql
2389- /// -- typed
2387+ /// -- typed, specific to bigquery
23902388 /// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
23912389 /// -- typeless
23922390 /// STRUCT( expr1 [AS field_name] [, ... ])
23932391 /// ```
2394- fn parse_bigquery_struct_literal(&mut self) -> Result<Expr, ParserError> {
2395- let (fields, trailing_bracket) =
2396- self.parse_struct_type_def(Self::parse_struct_field_def)?;
2397- if trailing_bracket.0 {
2398- return parser_err!(
2392+ fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
2393+ let mut fields = vec![];
2394+ // Typed struct syntax is only supported by BigQuery
2395+ // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
2396+ if self.dialect.supports_typed_struct_syntax() {
2397+ self.prev_token();
2398+ let trailing_bracket;
2399+ (fields, trailing_bracket) =
2400+ self.parse_struct_type_def(Self::parse_struct_field_def)?;
2401+ if trailing_bracket.0 {
2402+ return parser_err!(
23992403 "unmatched > in STRUCT literal",
24002404 self.peek_token().span.start
24012405 );
2406+ }
24022407 }
24032408
24042409 self.expect_token(&Token::LParen)?;
@@ -2409,13 +2414,13 @@ impl<'a> Parser<'a> {
24092414 Ok(Expr::Struct { values, fields })
24102415 }
24112416
2412- /// Parse an expression value for a bigquery struct [1]
2417+ /// Parse an expression value for a struct literal
24132418 /// Syntax
24142419 /// ```sql
24152420 /// expr [AS name]
24162421 /// ```
24172422 ///
2418- /// Parameter typed_syntax is set to true if the expression
2423+ /// For biquery [1], Parameter typed_syntax is set to true if the expression
24192424 /// is to be parsed as a field expression declared using typed
24202425 /// struct syntax [2], and false if using typeless struct syntax [3].
24212426 ///
0 commit comments