-- -- composition_rel__check_path_exists_p/2 -- create or replace function composition_rel__check_path_exists_p( integer, integer ) returns bool as $$ declare component_id alias for $1; container_id alias for $2; row record; begin if component_id = container_id then return 't'; end if; for row in select r.object_id_one as parent_id from acs_rels r, composition_rels c where r.rel_id = c.rel_id and r.object_id_two = component_id LOOP if composition_rel__check_path_exists_p(row.parent_id, container_id) = 't' then return 't'; end if; end loop; return 'f'; end;$$ language plpgsql;