Skip to content

Instantly share code, notes, and snippets.

@pytlv
Created November 20, 2023 15:59
Show Gist options
  • Select an option

  • Save pytlv/f7fc5f20e9eddae5c740350defcbcc94 to your computer and use it in GitHub Desktop.

Select an option

Save pytlv/f7fc5f20e9eddae5c740350defcbcc94 to your computer and use it in GitHub Desktop.
add last_modified column to an sqlite3 database
ALTER TABLE your_table
ADD COLUMN last_update TEXT;
CREATE TRIGGER update_last_update
AFTER UPDATE
ON Your_Table_Name
FOR EACH ROW
BEGIN
UPDATE Your_Table_Name
SET last_update = CURRENT_TIMESTAMP
WHERE id = NEW.id;
END;
PRAGMA recursive_triggers = OFF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment