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

@ -3413,6 +3413,13 @@ pub enum Statement {
partitioned: Option<Vec<Expr>>,
table_format: Option<HiveLoadDataFormat>,
},
/// ```sql
/// Rename TABLE tbl_name TO new_tbl_name[, tbl_name2 TO new_tbl_name2] ...
/// ```
/// Renames one or more tables
///
/// See Mysql <https://dev.mysql.com/doc/refman/9.1/en/rename-table.html>
RenameTable(Vec<RenameTable>),
}
impl fmt::Display for Statement {
@ -4970,6 +4977,9 @@ impl fmt::Display for Statement {
}
Ok(())
}
Statement::RenameTable(rename_tables) => {
write!(f, "RENAME TABLE {}", display_comma_separated(rename_tables))
}
}
}
}
@ -7672,6 +7682,22 @@ impl Display for JsonNullClause {
}
}
/// rename object definition
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
pub struct RenameTable {
pub old_name: ObjectName,
pub new_name: ObjectName,
}
impl fmt::Display for RenameTable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} TO {}", self.old_name, self.new_name)?;
Ok(())
}
}
#[cfg(test)]
mod tests {
use super::*;