postgresql7.1 select count(*) from acs_rel_types t where (t.object_type_one = :group_type or acs_object_type__is_subtype_p(t.object_type_one, :group_type) = 't') and t.rel_type = :rel_type select case when exists (select 1 from group_rels where group_id = :group_id and rel_type = :rel_type) then 1 else 0 end select case when exists (select 1 from rel_segments s where s.group_id = :group_id and s.rel_type = :rel_type) then 1 else 0 end