For hierarchical data, I like to split the hierarchy. For example, if we are dealing with a hierarchy of employees, I usually do something like this -
create table employee ( id serial primary key, name varchar(50)); create table roster ( id serial primary key, employee_id int references employee (id), supervisor_id int references employee (id));
This can be extended to provide historical hierarchies by adding the row_date or start_date and stop_date to the roster table.
Make sure you have unique constraints and triggers that apply where applicable to enforce business rules.
source share