--
-- rel_segment__delete/1
--
create or replace function rel_segment__delete(
  integer
) returns int4 as $$

declare
  delete__segment_id            alias for $1;  
  row                           record;
begin

   -- remove all constraints on this segment
   for row in  select constraint_id 
                 from rel_constraints 
                where rel_segment = delete__segment_id 
   LOOP

       PERFORM rel_constraint__delete(row.constraint_id);

   end loop;

   PERFORM party__delete(delete__segment_id);

   return 0; 
end;$$ language plpgsql;