Using `nextval` and `currval` inside one CREATE TABLE
The code you have posted works OK, and is guaranteed to insert the same IDs. 

The other way of designing this is to have a separate table that stores the hierarchical relationships, but you don't really need to do so unless you have many:1 or many:many relationships.