@@ -2854,3 +2854,73 @@ fn parse_mssql_update_with_output_into() {
28542854 "UPDATE employees SET salary = salary * 1.1 OUTPUT INSERTED.id, DELETED.salary, INSERTED.salary INTO @changes WHERE department = 'Engineering'" ,
28552855 ) ;
28562856}
2857+
2858+ #[ test]
2859+ fn parse_mssql_go_keyword ( ) {
2860+ let single_go_keyword = "USE some_database;\n GO" ;
2861+ let stmts = ms ( ) . parse_sql_statements ( single_go_keyword) . unwrap ( ) ;
2862+ assert_eq ! ( stmts. len( ) , 2 ) ;
2863+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: None } ) , ) ;
2864+
2865+ let go_with_count = "SELECT 1;\n GO 5" ;
2866+ let stmts = ms ( ) . parse_sql_statements ( go_with_count) . unwrap ( ) ;
2867+ assert_eq ! ( stmts. len( ) , 2 ) ;
2868+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: Some ( 5 ) } ) ) ;
2869+
2870+ let bare_go = "GO" ;
2871+ let stmts = ms ( ) . parse_sql_statements ( bare_go) . unwrap ( ) ;
2872+ assert_eq ! ( stmts. len( ) , 1 ) ;
2873+ assert_eq ! ( stmts[ 0 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2874+
2875+ let go_then_statements = "/* whitespace */ GO\n RAISERROR('This is a test', 16, 1);" ;
2876+ let stmts = ms ( ) . parse_sql_statements ( go_then_statements) . unwrap ( ) ;
2877+ assert_eq ! ( stmts. len( ) , 2 ) ;
2878+ assert_eq ! ( stmts[ 0 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2879+ assert_eq ! (
2880+ stmts[ 1 ] ,
2881+ Statement :: RaisError {
2882+ message: Box :: new( Expr :: Value (
2883+ ( Value :: SingleQuotedString ( "This is a test" . to_string( ) ) ) . with_empty_span( )
2884+ ) ) ,
2885+ severity: Box :: new( Expr :: Value ( number( "16" ) . with_empty_span( ) ) ) ,
2886+ state: Box :: new( Expr :: Value ( number( "1" ) . with_empty_span( ) ) ) ,
2887+ arguments: vec![ ] ,
2888+ options: vec![ ] ,
2889+ }
2890+ ) ;
2891+
2892+ let multiple_gos = "SELECT 1;\n GO 5\n SELECT 2;\n GO" ;
2893+ let stmts = ms ( ) . parse_sql_statements ( multiple_gos) . unwrap ( ) ;
2894+ assert_eq ! ( stmts. len( ) , 4 ) ;
2895+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: Some ( 5 ) } ) ) ;
2896+ assert_eq ! ( stmts[ 3 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2897+
2898+ let comment_following_go = "USE some_database;\n GO -- okay" ;
2899+ let stmts = ms ( ) . parse_sql_statements ( comment_following_go) . unwrap ( ) ;
2900+ assert_eq ! ( stmts. len( ) , 2 ) ;
2901+ assert_eq ! ( stmts[ 1 ] , Statement :: Go ( GoStatement { count: None } ) ) ;
2902+
2903+ let actually_column_alias = "SELECT NULL AS GO" ;
2904+ let stmt = ms ( ) . verified_only_select ( actually_column_alias) ;
2905+ assert_eq ! (
2906+ only( stmt. projection) ,
2907+ SelectItem :: ExprWithAlias {
2908+ expr: Expr :: Value ( Value :: Null . with_empty_span( ) ) ,
2909+ alias: Ident :: new( "GO" ) ,
2910+ }
2911+ ) ;
2912+
2913+ let invalid_go_position = "SELECT 1; GO" ;
2914+ let err = ms ( ) . parse_sql_statements ( invalid_go_position) ;
2915+ assert_eq ! (
2916+ err. unwrap_err( ) . to_string( ) ,
2917+ "sql parser error: Expected: newline before GO, found: ;"
2918+ ) ;
2919+
2920+ let invalid_go_count = "SELECT 1\n GO x" ;
2921+ let err = ms ( ) . parse_sql_statements ( invalid_go_count) ;
2922+ assert_eq ! (
2923+ err. unwrap_err( ) . to_string( ) ,
2924+ "sql parser error: Expected: end of statement, found: x"
2925+ ) ;
2926+ }
0 commit comments