Skip to content

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

Description

@ikatyal2110

When a table has an index on a column and you rename that column via transform(rename=...), a TransformError is raised even though the column still exists under its new name.

import sqlite_utils
db = sqlite_utils.Database(memory=True)
db["t"].insert({"id": 1, "name": "Alice"}, pk="id")
db["t"].create_index(["name"])
db["t"].transform(rename={"name": "full_name"})
# TransformError: Index 'idx_t_name' column 'name' is not in updated table 't'.

The error says the column "is not in updated table", but a renamed column is by definition still present. The check in _transform_sql() conflates col in rename (column still exists, just renamed) with col in drop (column truly removed). Only dropped columns make an index unrecoverable; renamed columns can have their index recreated using the new name.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions