DEV Community

Dimitrios Desyllas
Dimitrios Desyllas

Posted on

How to sync a Nested Set(self-referencing) table into closure table using triggers?

As I ask upon:

I try to sync a self-referencing table into a nested set one.

So far I manged to do it via insert trigger (for more clarity look at question):

CREATE TRIGGER "insert_sync_closure" ON files
AFTER insert AS
    INSERT INTO files_closure(parent_id,child_id)
    select files_closure.parent_id as parent_id , as child_id
    from INSERTED join files_closure on
    where  files_closure.child_id = INSERTED.folder

Enter fullscreen mode Exit fullscreen mode

And initialize it using a recusive SQL query. But I am kinda stuck upon updating it using a trigger upon delete and update.

May I have your help with that?

Top comments (0)