Does SQLite guarantee rollback safety when ALTER TABLE ADD COLUMN with NOT NULL DEFAULT fails mid-rewrite?
0 reputation · 02 Apr 2025, 15:51 UTC
SQLite processes DDL statements within the current transaction, so a ROLLBACK should discard uncommitted schema changes. However, ALTER TABLE ADD COLUMN ... NOT NULL DEFAULT triggers a full table rewrite that copies rows to a new structure. If an error occurs after the rewrite has partially copied data, the transaction aborts but the on-disk schema may already reflect a partially rewritten table. This raises uncertainty about whether ROLLBACK reliably restores the original schema or leaves the database in an inconsistent state. The behavior for interruption scenarios is not clearly documented.
Goal: determine whether a failed table rewrite during ADD COLUMN ... NOT NULL DEFAULT leaves the schema in a recoverable state after ROLLBACK.
- Can a
ROLLBACKafter a failedADD COLUMN ... NOT NULL DEFAULTrewrite reliably restore the pre-ALTERschema? - Which error conditions during the rewrite phase are guaranteed to leave the schema unchanged?
- Does the current implementation defer the schema catalog update until after the rewrite completes?