In SQLite, I have a tree-structured table called layer
with columns (id, ..., parentId)
. And a normal table called dir
with columns (id, ..., modifiedTime)
.The situation is:
Once some rows in dir
are updated with new modifiedTime, all parents of them should also be updated. Guarantee that the modifiedTime is non-decreasing.
Without a trigger, I could use this sql to do it(by using WITH RECURSIVE clause):
WITH RECURSIVE P(id) AS (
SELECT parentId FROM layer WHERE id="The Id of Modified Row"
UNION ALL
SELECT L.parentId FROM layer AS L, P WHERE L.id=P.id)
UPDATE dir SET modifiedT=CURRENT_TIMESTAMP WHERE id IN P;
But the UPDATE statement makes an error when I put the sql into a trigger. After reading the SQLite offical doc, I got that The WITH clause cannot be used within a CREATE TRIGGER.
That's the issue
How can I make the trigger do what I want?
In another word, how to replace the 'WITH' clause within a trigger?