There is a table, for example, I need to add the Lubelskie Voivodeship to Poland, the very branch of Poland is empty. To create a country, I use this code, but it requires the ID of the left element, and we have a branch empty
BEGIN; SELECT @treeRight := rgt FROM geo WHERE id = 16; /* справа от ветки Польща */ UPDATE geo SET rgt = rgt + 2 WHERE rgt > @treeRight; UPDATE geo SET lft = lft + 2 WHERE lft > @treeRight; INSERT INTO geo VALUES(0, 'Росія', @treeRight + 1, @treeRight + 2, 2); COMMIT; 