@@ -7383,6 +7383,33 @@ fn parse_recursive_cte() {
73837383 assert_eq ! ( with. cte_tables. first( ) . unwrap( ) , & expected) ;
73847384}
73857385
7386+ #[ test]
7387+ fn parse_cte_in_data_modification_statements ( ) {
7388+ match verified_stmt ( "WITH x AS (SELECT 1) UPDATE t SET bar = (SELECT * FROM x)" ) {
7389+ Statement :: Query ( query) => {
7390+ assert_eq ! ( query. with. unwrap( ) . to_string( ) , "WITH x AS (SELECT 1)" ) ;
7391+ assert ! ( matches!( * query. body, SetExpr :: Update ( _) ) ) ;
7392+ }
7393+ other => panic ! ( "Expected: UPDATE, got: {:?}" , other) ,
7394+ }
7395+
7396+ match verified_stmt ( "WITH t (x) AS (SELECT 9) DELETE FROM q WHERE id IN (SELECT x FROM t)" ) {
7397+ Statement :: Query ( query) => {
7398+ assert_eq ! ( query. with. unwrap( ) . to_string( ) , "WITH t (x) AS (SELECT 9)" ) ;
7399+ assert ! ( matches!( * query. body, SetExpr :: Delete ( _) ) ) ;
7400+ }
7401+ other => panic ! ( "Expected: DELETE, got: {:?}" , other) ,
7402+ }
7403+
7404+ match verified_stmt ( "WITH x AS (SELECT 42) INSERT INTO t SELECT foo FROM x" ) {
7405+ Statement :: Query ( query) => {
7406+ assert_eq ! ( query. with. unwrap( ) . to_string( ) , "WITH x AS (SELECT 42)" ) ;
7407+ assert ! ( matches!( * query. body, SetExpr :: Insert ( _) ) ) ;
7408+ }
7409+ other => panic ! ( "Expected: INSERT, got: {:?}" , other) ,
7410+ }
7411+ }
7412+
73867413#[ test]
73877414fn parse_derived_tables ( ) {
73887415 let sql = "SELECT a.x, b.y FROM (SELECT x FROM foo) AS a CROSS JOIN (SELECT y FROM bar) AS b" ;
0 commit comments