How to use CTE's with update/delete on SQLite?

SQLite now has CTEs, and the documentation says you can use it with insert, update and delete queries -- but only gives examples of select statements.

I can figure out how CTEs apply to inserts, via insert-select; but how can we use them in update or delete, where there is no from-clause?

Answers


CTEs can be used in subqueries:

WITH NewNames(ID, Name) AS (...)
UPDATE MyTable
SET Name = (SELECT Name
            FROM NewNames
            WHERE ID = MyTable.ID);

WITH IDsToDelete AS (...)
DELETE FROM MyTable
WHERE ID IN IDsToDelete;

Need Your Help

Ending a function in C++

c++ qt function

I have a C++ function called write() that is supposed to write a large number of bytes on the users HDD. This woud normally take more than 30 seconds, so I want to give the user the ability to Abort