@@ -6539,7 +6539,17 @@ fn parse_multiple_statements() {
6539
6539
) ;
6540
6540
test_with ( "DELETE FROM foo" , "SELECT" , " bar" ) ;
6541
6541
test_with ( "INSERT INTO foo VALUES (1)" , "SELECT" , " bar" ) ;
6542
- test_with ( "CREATE TABLE foo (baz INT)" , "SELECT" , " bar" ) ;
6542
+ // Since MySQL supports the `CREATE TABLE SELECT` syntax, this needs to be handled separately
6543
+ let res = parse_sql_statements ( "CREATE TABLE foo (baz INT); SELECT bar" ) ;
6544
+ assert_eq ! (
6545
+ vec![
6546
+ one_statement_parses_to( "CREATE TABLE foo (baz INT)" , "" ) ,
6547
+ one_statement_parses_to( "SELECT bar" , "" ) ,
6548
+ ] ,
6549
+ res. unwrap( )
6550
+ ) ;
6551
+ // Check that extra semicolon at the end is stripped by normalization:
6552
+ one_statement_parses_to ( "CREATE TABLE foo (baz INT);" , "CREATE TABLE foo (baz INT)" ) ;
6543
6553
// Make sure that empty statements do not cause an error:
6544
6554
let res = parse_sql_statements ( ";;" ) ;
6545
6555
assert_eq ! ( 0 , res. unwrap( ) . len( ) ) ;
@@ -11532,3 +11542,24 @@ fn test_select_top() {
11532
11542
dialects. verified_stmt ( "SELECT TOP 3 DISTINCT * FROM tbl" ) ;
11533
11543
dialects. verified_stmt ( "SELECT TOP 3 DISTINCT a, b, c FROM tbl" ) ;
11534
11544
}
11545
+
11546
+ #[ test]
11547
+ fn parse_create_table_select ( ) {
11548
+ let dialects = all_dialects_where ( |d| d. supports_create_table_select ( ) ) ;
11549
+ let sql_1 = r#"CREATE TABLE foo (baz INT) SELECT bar"# ;
11550
+ let expected = r#"CREATE TABLE foo (baz INT) AS SELECT bar"# ;
11551
+ let _ = dialects. one_statement_parses_to ( sql_1, expected) ;
11552
+
11553
+ let sql_2 = r#"CREATE TABLE foo (baz INT, name STRING) SELECT bar, oth_name FROM test.table_a"# ;
11554
+ let expected =
11555
+ r#"CREATE TABLE foo (baz INT, name STRING) AS SELECT bar, oth_name FROM test.table_a"# ;
11556
+ let _ = dialects. one_statement_parses_to ( sql_2, expected) ;
11557
+
11558
+ let dialects = all_dialects_where ( |d| !d. supports_create_table_select ( ) ) ;
11559
+ for sql in [ sql_1, sql_2] {
11560
+ assert_eq ! (
11561
+ dialects. parse_sql_statements( & sql) . unwrap_err( ) ,
11562
+ ParserError :: ParserError ( "Expected: end of statement, found: SELECT" . to_string( ) )
11563
+ ) ;
11564
+ }
11565
+ }
0 commit comments