Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSERT INTO parent_of (id, parent_id, isdir, name)
- VALUES (1, NULL, 1, 'root')
- , (2, 1, 0, 'file1')
- , (3, 1, 1, 'dir1')
- , (4, 1, 0, 'file2')
- , (5, 1, 1, 'dir2')
- , (6, 5, 0, 'file3')
- , (8, 7, 0, 'file4'); -- last one is orphan
- /* paths:
- 1 root
- 2 root\file1
- 3 root\dir1
- 4 root\file2
- 5 root\dir2
- 6 root\dir2\file3
- */
- INSERT INTO parent_of VALUES (7, 5, 1, 'dir3'); -- orphan is resolved after this is inserted
- /* paths:
- 1 root
- 2 root\file1
- 3 root\dir1
- 4 root\file2
- 5 root\dir2
- 6 root\dir2\file3
- 7 root\dir2\dir3
- 8 root\dir2\dir3\file4
- */
- UPDATE parent_of -- move entire subtree '/dir2' to '/dir1/dir2'
- SET parent_id = 3
- WHERE id = 5;
- /* paths:
- 1 root
- 2 root\file1
- 3 root\dir1
- 4 root\file2
- 5 root\dir1\dir2
- 6 root\dir1\dir2\file3
- 7 root\dir1\dir2\dir3
- 8 root\dir1\dir2\dir3\file4
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement