Skip to content

Fix transform() raising TransformError when renaming an indexed column - #823

Closed
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-transform-rename-index
Closed

ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-transform-rename-index

Conversation

@ikatyal2110

@ikatyal2110 ikatyal2110 commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

When a column that has an index is renamed via transform(rename=...), the index can be recreated using the new column name — the error was wrong to treat renaming the same as dropping. The fix updates the stored index SQL to reference the new column name instead of raising TransformError. Fixes #822.


Generated by Claude Code


📚 Documentation preview 📚: https://sqlite-utils--823.org.readthedocs.build/en/823/

Renaming a column that has an index is valid — the index should be
recreated using the new column name. Only dropping a column makes an
index unrecoverable and warrants the error.
Comment thread sqlite_utils/db.py
Comment on lines +2861 to +2864
elif col in rename:
index_sql = index_sql.replace(
quote_identifier(col), quote_identifier(rename[col])
)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels too risk, I'm going to look for a better way.

@simonw

simonw commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Fixed in 57192ef

@simonw simonw closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transform(rename=...) raises TransformError when the renamed column has an index

3 participants