@@ -1160,9 +1160,8 @@ impl<'a> Parser<'a> {
1160
1160
Keyword::MATCH if dialect_of!(self is MySqlDialect | GenericDialect) => {
1161
1161
self.parse_match_against()
1162
1162
}
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()
1166
1165
}
1167
1166
Keyword::PRIOR if matches!(self.state, ParserState::ConnectBy) => {
1168
1167
let expr = self.parse_subexpr(self.dialect.prec_value(Precedence::PlusMinus))?;
@@ -2328,19 +2327,25 @@ impl<'a> Parser<'a> {
2328
2327
}
2329
2328
}
2330
2329
2331
- /// Bigquery specific: Parse a struct literal
2332
2330
/// Syntax
2333
2331
/// ```sql
2334
- /// -- typed
2332
+ /// -- typed, specific to bigquery
2335
2333
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
2336
2334
/// -- typeless
2337
2335
/// STRUCT( expr1 [AS field_name] [, ... ])
2338
2336
/// ```
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
+ }
2344
2349
}
2345
2350
2346
2351
self.expect_token(&Token::LParen)?;
@@ -2351,13 +2356,13 @@ impl<'a> Parser<'a> {
2351
2356
Ok(Expr::Struct { values, fields })
2352
2357
}
2353
2358
2354
- /// Parse an expression value for a bigquery struct [1]
2359
+ /// Parse an expression value for a struct literal
2355
2360
/// Syntax
2356
2361
/// ```sql
2357
2362
/// expr [AS name]
2358
2363
/// ```
2359
2364
///
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
2361
2366
/// is to be parsed as a field expression declared using typed
2362
2367
/// struct syntax [2], and false if using typeless struct syntax [3].
2363
2368
///
0 commit comments