table.duplicate(new_table_name) feature, closes #449

Thanks, @davidleejy
This commit is contained in:
David 2022-07-16 05:21:36 +08:00 committed by GitHub
commit b366e68deb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View file

@ -1476,6 +1476,21 @@ class Table(Queryable):
)
return self
def duplicate(self, name_new: str) -> "Table":
"""
Duplicate this table in this database.
:param name_new: Name of new table.
"""
assert self.exists()
with self.db.conn:
sql = "CREATE TABLE [{new_table}] AS SELECT * FROM [{table}];".format(
new_table=name_new,
table=self.name,
)
self.db.execute(sql)
return self.db[name_new]
def transform(
self,
*,