A query that updates all nodes, starting from some node to the root, is very similar:
WITH RECURSIVE d AS (
SELECT user_id
FROM btrees
WHERE user_id = :node_id
UNION ALL
SELECT c.user_id
FROM d JOIN btrees c ON d.parent_id = c.user_id
)
UPDATE btrees b set lft = 1
FROM d
WHERE d.user_id = b.user_id
Please note that the condition in the connection is canceled.
In general, recursive queries work as follows:
- UNION ALL WITH RECURSIVE.
- UNION ALL , . . .
- 2 , - .