@@ -1123,9 +1123,8 @@ impl<'a> Parser<'a> {
1123
1123
Keyword::MATCH if dialect_of!(self is MySqlDialect | GenericDialect) => {
1124
1124
Ok(Some(self.parse_match_against()?))
1125
1125
}
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()?))
1129
1128
}
1130
1129
Keyword::PRIOR if matches!(self.state, ParserState::ConnectBy) => {
1131
1130
let expr = self.parse_subexpr(self.dialect.prec_value(Precedence::PlusMinus))?;
@@ -2383,15 +2382,16 @@ impl<'a> Parser<'a> {
2383
2382
}
2384
2383
}
2385
2384
2386
- /// Bigquery specific: Parse a struct literal
2387
2385
/// Syntax
2388
2386
/// ```sql
2389
2387
/// -- typed
2390
2388
/// STRUCT<[field_name] field_type, ...>( expr1 [, ... ])
2391
2389
/// -- typeless
2392
2390
/// STRUCT( expr1 [AS field_name] [, ... ])
2393
2391
/// ```
2394
- fn parse_bigquery_struct_literal(&mut self) -> Result<Expr, ParserError> {
2392
+ fn parse_struct_literal(&mut self) -> Result<Expr, ParserError> {
2393
+ // Parse the fields definition if exist `<[field_name] field_type, ...>`
2394
+ self.prev_token();
2395
2395
let (fields, trailing_bracket) =
2396
2396
self.parse_struct_type_def(Self::parse_struct_field_def)?;
2397
2397
if trailing_bracket.0 {
@@ -2401,6 +2401,7 @@ impl<'a> Parser<'a> {
2401
2401
);
2402
2402
}
2403
2403
2404
+ // Parse the struct values `(expr1 [, ... ])`
2404
2405
self.expect_token(&Token::LParen)?;
2405
2406
let values = self
2406
2407
.parse_comma_separated(|parser| parser.parse_struct_field_expr(!fields.is_empty()))?;
@@ -2409,13 +2410,13 @@ impl<'a> Parser<'a> {
2409
2410
Ok(Expr::Struct { values, fields })
2410
2411
}
2411
2412
2412
- /// Parse an expression value for a bigquery struct [1]
2413
+ /// Parse an expression value for a struct literal
2413
2414
/// Syntax
2414
2415
/// ```sql
2415
2416
/// expr [AS name]
2416
2417
/// ```
2417
2418
///
2418
- /// Parameter typed_syntax is set to true if the expression
2419
+ /// For biquery [1], Parameter typed_syntax is set to true if the expression
2419
2420
/// is to be parsed as a field expression declared using typed
2420
2421
/// struct syntax [2], and false if using typeless struct syntax [3].
2421
2422
///
0 commit comments