-
Notifications
You must be signed in to change notification settings - Fork 769
Open
Open
Copy link
Description
Description
When ALTER TABLE RENAME COLUMN renames a column referenced by a trigger via NEW.column, the trigger SQL text in sqlite_master is correctly rewritten but the compiled/cached trigger program is not re-compiled. Subsequent DML that fires the trigger fails.
Reproducer
CREATE TABLE t(id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE log(msg TEXT);
CREATE TRIGGER tr AFTER INSERT ON t
BEGIN
INSERT INTO log VALUES('name=' || NEW.name);
END;
INSERT INTO t VALUES(1,'test'); -- Works: log gets 'name=test'
ALTER TABLE t RENAME COLUMN name TO full_name;
-- Trigger SQL IS correctly updated:
-- SELECT sql FROM sqlite_master WHERE type='trigger';
-- -> ...NEW.full_name... (correct)
-- But INSERT fails because compiled trigger still uses 'name'
INSERT INTO t VALUES(2,'hello');
-- Turso: Parse error: no such column in NEW: name
-- SQLite: (succeeds, log gets 'name=hello')Error Message
Parse error: no such column in NEW: name
The ALTER TABLE RENAME COLUMN implementation correctly rewrites the trigger SQL text stored in sqlite_master but does not invalidate and re-compile the cached trigger program. SQLite invalidates all cached schema objects when a column is renamed, forcing re-compilation from the updated SQL text on next use.
This issue brought to you by Mikaël and Claude Code.
Reactions are currently unavailable