Add support for MYSQL's RENAME TABLE (#1616)

Co-authored-by: Ifeanyi Ubah <ify1992@yahoo.com>
This commit is contained in:
wugeer 2025-01-02 04:54:58 +08:00 committed by GitHub
parent 3bad04e9e8
commit 94ea20628f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 104 additions and 0 deletions

View file

@ -4133,6 +4133,65 @@ fn parse_alter_table() {
}
}
#[test]
fn parse_rename_table() {
match verified_stmt("RENAME TABLE test.test1 TO test_db.test2") {
Statement::RenameTable(rename_tables) => {
assert_eq!(
vec![RenameTable {
old_name: ObjectName(vec![
Ident::new("test".to_string()),
Ident::new("test1".to_string()),
]),
new_name: ObjectName(vec![
Ident::new("test_db".to_string()),
Ident::new("test2".to_string()),
]),
}],
rename_tables
);
}
_ => unreachable!(),
};
match verified_stmt(
"RENAME TABLE old_table1 TO new_table1, old_table2 TO new_table2, old_table3 TO new_table3",
) {
Statement::RenameTable(rename_tables) => {
assert_eq!(
vec![
RenameTable {
old_name: ObjectName(vec![Ident::new("old_table1".to_string())]),
new_name: ObjectName(vec![Ident::new("new_table1".to_string())]),
},
RenameTable {
old_name: ObjectName(vec![Ident::new("old_table2".to_string())]),
new_name: ObjectName(vec![Ident::new("new_table2".to_string())]),
},
RenameTable {
old_name: ObjectName(vec![Ident::new("old_table3".to_string())]),
new_name: ObjectName(vec![Ident::new("new_table3".to_string())]),
}
],
rename_tables
);
}
_ => unreachable!(),
};
assert_eq!(
parse_sql_statements("RENAME TABLE old_table TO new_table a").unwrap_err(),
ParserError::ParserError("Expected: end of statement, found: a".to_string())
);
assert_eq!(
parse_sql_statements("RENAME TABLE1 old_table TO new_table a").unwrap_err(),
ParserError::ParserError(
"Expected: KEYWORD `TABLE` after RENAME, found: TABLE1".to_string()
)
);
}
#[test]
fn test_alter_table_with_on_cluster() {
match all_dialects()