@@ -1160,9 +1160,8 @@ impl<'a> Parser<'a> {
11601160 Keyword::MATCH if dialect_of!(self is MySqlDialect | GenericDialect) => {
11611161 self.parse_match_against()
11621162 }
1163- Keyword::STRUCT if dialect_of!(self is BigQueryDialect | GenericDialect) => {
1164- self.prev_token();
1165- self.parse_bigquery_struct_literal()
1163+ Keyword::STRUCT if self.dialect.supports_struct_literal() => {
1164+ self.parse_struct_literal()
11661165 }
11671166 Keyword::PRIOR if matches!(self.state, ParserState::ConnectBy) => {
11681167 let expr = self.parse_subexpr(self.dialect.prec_value(Precedence::PlusMinus))?;
@@ -2328,19 +2327,25 @@ impl<'a> Parser<'a> {
23282327 }
23292328 }
23302329
2331- /// Bigquery specific: Parse a struct literal
23322330 /// Syntax
23332331 /// ```sql
2334- /// -- typed
2332+ /// -- typed, specific to bigquery
23352333 /// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
23362334 /// -- typeless
23372335 /// STRUCT( expr1 [AS field_name] [, ... ])
23382336 /// ```
2339- fn parse_bigquery_struct_literal(&mut self) -> Result<Expr, ParserError> {
2340- let (fields, trailing_bracket) =
2341- self.parse_struct_type_def(Self::parse_struct_field_def)?;
2342- if trailing_bracket.0 {
2343- return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
2337+ fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
2338+ let mut fields = vec![];
2339+ // Typed struct syntax is only supported by BigQuery
2340+ // https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#typed_struct_syntax
2341+ if self.dialect.supports_typed_struct_syntax() {
2342+ self.prev_token();
2343+ let trailing_bracket;
2344+ (fields, trailing_bracket) =
2345+ self.parse_struct_type_def(Self::parse_struct_field_def)?;
2346+ if trailing_bracket.0 {
2347+ return parser_err!("unmatched > in STRUCT literal", self.peek_token().location);
2348+ }
23442349 }
23452350
23462351 self.expect_token(&Token::LParen)?;
@@ -2351,13 +2356,13 @@ impl<'a> Parser<'a> {
23512356 Ok(Expr::Struct { values, fields })
23522357 }
23532358
2354- /// Parse an expression value for a bigquery struct [1]
2359+ /// Parse an expression value for a struct literal
23552360 /// Syntax
23562361 /// ```sql
23572362 /// expr [AS name]
23582363 /// ```
23592364 ///
2360- /// Parameter typed_syntax is set to true if the expression
2365+ /// For biquery [1], Parameter typed_syntax is set to true if the expression
23612366 /// is to be parsed as a field expression declared using typed
23622367 /// struct syntax [2], and false if using typeless struct syntax [3].
23632368 ///
0 commit comments