--
-- acs_object_type__is_subtype_p/2
--
create or replace function acs_object_type__is_subtype_p(
  character varying,
  character varying
) returns bool as $$

declare
  is_subtype_p__object_type_1          alias for $1;  
  is_subtype_p__object_type_2          alias for $2;  
  v_result                             integer;       
begin
    -- select count(*) into v_result
    --  where exists (select 1 
    --                 from acs_object_types t 
    --                where t.object_type	= is_subtype_p__object_type_2
    --              connect by prior t.object_type = t.supertype
    --                start with t.supertype = is_subtype_p__object_type_1);

    select count(*) into v_result
     where exists (select 1 
                     from acs_object_types t, acs_object_types t2
                    where t.object_type = is_subtype_p__object_type_2
                      and t2.object_type = is_subtype_p__object_type_1
                      and t.tree_sortkey between t2.tree_sortkey and tree_right(t2.tree_sortkey));

    if v_result > 0 then
       return 't';
    end if;

    return 'f';
   
end;$$ language plpgsql;