PL/PgSQL functions for creating and deleting a hierarchy of an unknown depth.