mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 06:54:07 +00:00
add support for with
clauses (CTEs) in delete
statements (#1764)
This commit is contained in:
parent
1e54a34acd
commit
3392623b00
4 changed files with 52 additions and 0 deletions
|
@ -7383,6 +7383,33 @@ fn parse_recursive_cte() {
|
|||
assert_eq!(with.cte_tables.first().unwrap(), &expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_cte_in_data_modification_statements() {
|
||||
match verified_stmt("WITH x AS (SELECT 1) UPDATE t SET bar = (SELECT * FROM x)") {
|
||||
Statement::Query(query) => {
|
||||
assert_eq!(query.with.unwrap().to_string(), "WITH x AS (SELECT 1)");
|
||||
assert!(matches!(*query.body, SetExpr::Update(_)));
|
||||
}
|
||||
other => panic!("Expected: UPDATE, got: {:?}", other),
|
||||
}
|
||||
|
||||
match verified_stmt("WITH t (x) AS (SELECT 9) DELETE FROM q WHERE id IN (SELECT x FROM t)") {
|
||||
Statement::Query(query) => {
|
||||
assert_eq!(query.with.unwrap().to_string(), "WITH t (x) AS (SELECT 9)");
|
||||
assert!(matches!(*query.body, SetExpr::Delete(_)));
|
||||
}
|
||||
other => panic!("Expected: DELETE, got: {:?}", other),
|
||||
}
|
||||
|
||||
match verified_stmt("WITH x AS (SELECT 42) INSERT INTO t SELECT foo FROM x") {
|
||||
Statement::Query(query) => {
|
||||
assert_eq!(query.with.unwrap().to_string(), "WITH x AS (SELECT 42)");
|
||||
assert!(matches!(*query.body, SetExpr::Insert(_)));
|
||||
}
|
||||
other => panic!("Expected: INSERT, got: {:?}", other),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_derived_tables() {
|
||||
let sql = "SELECT a.x, b.y FROM (SELECT x FROM foo) AS a CROSS JOIN (SELECT y FROM bar) AS b";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue