.transform() now preserves rowid values

* .transform() now preserves rowid values, refs #592
* Test transform rowids against different table types, closes #592
This commit is contained in:
Simon Willison 2023-09-08 17:45:30 -07:00 committed by GitHub
commit 1c6ea54338
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 13 deletions

View file

@ -1917,6 +1917,10 @@ class Table(Queryable):
for from_, to_ in copy_from_to.items():
old_cols.append(from_)
new_cols.append(to_)
# Ensure rowid is copied too
if "rowid" not in new_cols:
new_cols.insert(0, "rowid")
old_cols.insert(0, "rowid")
copy_sql = "INSERT INTO [{new_table}] ({new_cols})\n SELECT {old_cols} FROM [{old_table}];".format(
new_table=new_table_name,
old_table=self.name,