@@ -1118,9 +1118,8 @@ impl<'a> Parser<'a> {
11181118 Keyword::MATCH if dialect_of!(self is MySqlDialect | GenericDialect) => {
11191119 Ok(Some(self.parse_match_against()?))
11201120 }
1121- Keyword::STRUCT if dialect_of!(self is BigQueryDialect | GenericDialect) => {
1122- self.prev_token();
1123- Ok(Some(self.parse_bigquery_struct_literal()?))
1121+ Keyword::STRUCT if self.dialect.supports_struct_literal() => {
1122+ Ok(Some(self.parse_struct_literal()?))
11241123 }
11251124 Keyword::PRIOR if matches!(self.state, ParserState::ConnectBy) => {
11261125 let expr = self.parse_subexpr(self.dialect.prec_value(Precedence::PlusMinus))?;
@@ -2369,19 +2368,25 @@ impl<'a> Parser<'a> {
23692368 }
23702369 }
23712370
2372- /// Bigquery specific: Parse a struct literal
23732371 /// Syntax
23742372 /// ```sql
2375- /// -- typed
2373+ /// -- typed, specific to bigquery
23762374 /// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
23772375 /// -- typeless
23782376 /// STRUCT( expr1 [AS field_name] [, ... ])
23792377 /// ```
2380- fn parse_bigquery_struct_literal(&mut self) -> Result<Expr, ParserError> {
2381- let (fields, trailing_bracket) =
2382- self.parse_struct_type_def(Self::parse_struct_field_def)?;
2383- if trailing_bracket.0 {
2384- return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
2378+ fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
2379+ let mut fields = vec![];
2380+ // Typed struct syntax is only supported by BigQuery
2381+ // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
2382+ if self.dialect.supports_typed_struct_syntax() {
2383+ self.prev_token();
2384+ let trailing_bracket;
2385+ (fields, trailing_bracket) =
2386+ self.parse_struct_type_def(Self::parse_struct_field_def)?;
2387+ if trailing_bracket.0 {
2388+ return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
2389+ }
23852390 }
23862391
23872392 self.expect_token(&Token::LParen)?;
@@ -2392,13 +2397,13 @@ impl<'a> Parser<'a> {
23922397 Ok(Expr::Struct { values, fields })
23932398 }
23942399
2395- /// Parse an expression value for a bigquery struct [1]
2400+ /// Parse an expression value for a struct literal
23962401 /// Syntax
23972402 /// ```sql
23982403 /// expr [AS name]
23992404 /// ```
24002405 ///
2401- /// Parameter typed_syntax is set to true if the expression
2406+ /// For biquery [1], Parameter typed_syntax is set to true if the expression
24022407 /// is to be parsed as a field expression declared using typed
24032408 /// struct syntax [2], and false if using typeless struct syntax [3].
24042409 ///
0 commit comments