@@ -6210,16 +6210,10 @@ impl<'a> Parser<'a> {
6210
6210
} else {
6211
6211
let name = self . parse_object_name ( ) ?;
6212
6212
6213
- let partitions = if dialect_of ! ( self is MySqlDialect )
6213
+ let partitions: Vec < Ident > = if dialect_of ! ( self is MySqlDialect | GenericDialect )
6214
6214
&& self . parse_keyword ( Keyword :: PARTITION )
6215
6215
{
6216
- let mut partitions = self . parse_comma_separated ( |p| p. parse_tuple ( true , false ) ) ?;
6217
- if partitions. len ( ) != 1 {
6218
- return Err ( ParserError :: ParserError ( format ! (
6219
- "Partition expect one tuple"
6220
- ) ) ) ;
6221
- }
6222
- partitions. remove ( 0 )
6216
+ self . parse_partitions ( ) ?
6223
6217
} else {
6224
6218
vec ! [ ]
6225
6219
} ;
@@ -7430,6 +7424,37 @@ impl<'a> Parser<'a> {
7430
7424
representation : UserDefinedTypeRepresentation :: Composite { attributes } ,
7431
7425
} )
7432
7426
}
7427
+
7428
+ fn parse_partitions ( & mut self ) -> Result < Vec < Ident > , ParserError > {
7429
+ let mut partition_exprs: Vec < Expr > = self . parse_comma_separated ( Parser :: parse_expr) ?;
7430
+
7431
+ if partition_exprs. len ( ) == 1 {
7432
+ match partition_exprs. remove ( 0 ) {
7433
+ Expr :: Tuple ( exprs) => {
7434
+ let mut partitions: Vec < Ident > = Vec :: with_capacity ( exprs. len ( ) ) ;
7435
+ for expr in exprs {
7436
+ match expr {
7437
+ Expr :: Identifier ( ident) => partitions. push ( ident. clone ( ) ) ,
7438
+ _ => {
7439
+ return Err ( ParserError :: ParserError (
7440
+ "Partition expect one identifier" . to_string ( ) ,
7441
+ ) ) ;
7442
+ }
7443
+ }
7444
+ }
7445
+ return Ok ( partitions) ;
7446
+ }
7447
+ _ => {
7448
+ return Err ( ParserError :: ParserError (
7449
+ "Partition expect one tuple" . to_string ( ) ,
7450
+ ) ) ;
7451
+ }
7452
+ }
7453
+ }
7454
+ Err ( ParserError :: ParserError (
7455
+ "Partition expect one tuple" . to_string ( ) ,
7456
+ ) )
7457
+ }
7433
7458
}
7434
7459
7435
7460
impl Word {
@@ -8065,13 +8090,7 @@ mod tests {
8065
8090
if let TableFactor :: Table { partitions, .. } = table_factor {
8066
8091
let actual: Vec < & str > = partitions
8067
8092
. iter ( )
8068
- . map ( |expr| {
8069
- if let Expr :: Identifier ( ident) = & expr {
8070
- ident. value . as_str ( )
8071
- } else {
8072
- ""
8073
- }
8074
- } )
8093
+ . map ( |ident| ident. value . as_str ( ) )
8075
8094
. collect ( ) ;
8076
8095
assert_eq ! ( expected, actual) ;
8077
8096
}
0 commit comments