SQLite Forum

Displaying progress state during DELETE execution
Login
> <code>e.g.
DELETE FROM LogBook_LID WHERE DATETIME(TimeStampUtc) < DATETIME('now', '-5 years')</code>

I'm curious what's taking the time.  Is it the search to find out which rows to delete ?  Or the actual deletion because many rows are found ?

First, do you have an index on the <code>TimeStampUtc</code> column ?

Second, have you tried rephrasing the <code>WHERE</code> clause to allow SQLite to search that column directly ?  It should be something like

<code>DELETE FROM LogBook_LID WHERE TimeStampUtc < strftime('%s',DATETIME('now', '-5 years'))</code>

This would allow the search (thought not necessarily the deletion) to be done far faster.  So much faster that you might not need a progress display.