@@ -6277,6 +6277,14 @@ impl<'a> Parser<'a> {
62776277 } else {
62786278 let name = self . parse_object_name ( ) ?;
62796279
6280+ let partitions: Vec < Ident > = if dialect_of ! ( self is MySqlDialect | GenericDialect )
6281+ && self . parse_keyword ( Keyword :: PARTITION )
6282+ {
6283+ self . parse_partitions ( ) ?
6284+ } else {
6285+ vec ! [ ]
6286+ } ;
6287+
62806288 // Parse potential version qualifier
62816289 let version = self . parse_table_version ( ) ?;
62826290
@@ -6311,6 +6319,7 @@ impl<'a> Parser<'a> {
63116319 args,
63126320 with_hints,
63136321 version,
6322+ partitions,
63146323 } )
63156324 }
63166325 }
@@ -7483,6 +7492,13 @@ impl<'a> Parser<'a> {
74837492 representation : UserDefinedTypeRepresentation :: Composite { attributes } ,
74847493 } )
74857494 }
7495+
7496+ fn parse_partitions ( & mut self ) -> Result < Vec < Ident > , ParserError > {
7497+ self . expect_token ( & Token :: LParen ) ?;
7498+ let partitions = self . parse_comma_separated ( Parser :: parse_identifier) ?;
7499+ self . expect_token ( & Token :: RParen ) ?;
7500+ Ok ( partitions)
7501+ }
74867502}
74877503
74887504impl Word {
@@ -8100,4 +8116,29 @@ mod tests {
81008116 "sql parser error: Unexpected token following period in identifier: *" ,
81018117 ) ;
81028118 }
8119+
8120+ #[ test]
8121+ fn test_mysql_partition_selection ( ) {
8122+ let sql = "SELECT * FROM employees PARTITION (p0, p2)" ;
8123+ let expected = vec ! [ "p0" , "p2" ] ;
8124+
8125+ let ast: Vec < Statement > = Parser :: parse_sql ( & MySqlDialect { } , sql) . unwrap ( ) ;
8126+ assert_eq ! ( ast. len( ) , 1 ) ;
8127+ if let Statement :: Query ( v) = & ast[ 0 ] {
8128+ if let SetExpr :: Select ( select) = & * v. body {
8129+ assert_eq ! ( select. from. len( ) , 1 ) ;
8130+ let from: & TableWithJoins = & select. from [ 0 ] ;
8131+ let table_factor = & from. relation ;
8132+ if let TableFactor :: Table { partitions, .. } = table_factor {
8133+ let actual: Vec < & str > = partitions
8134+ . iter ( )
8135+ . map ( |ident| ident. value . as_str ( ) )
8136+ . collect ( ) ;
8137+ assert_eq ! ( expected, actual) ;
8138+ }
8139+ }
8140+ } else {
8141+ panic ! ( "fail to parse mysql partition selection" ) ;
8142+ }
8143+ }
81038144}
0 commit comments