--
-- tree_root_key/1
--
create or replace function tree_root_key(
  bit varying
) returns varbit as $$


-- Return the tree_sortkey for the root node of the node with the 
-- given tree_sortkey.  

declare
  p_tree_key      alias for $1;
begin

  if substring(p_tree_key, 1, 1) = '1' then
      return substring(p_tree_key, 1, 32);
  else
      return substring(p_tree_key, 1, 8);
  end if;

end;$$ language plpgsql;