postgresql7.1 select case when exists (select 1 from rel_segments s where s.segment_id <> :segment_id) then 1 else 0 end