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