All pastes #953638 Raw Edit

Miscellany

public text v1 · immutable
#953638 ·published 2008-03-23 06:23 UTC
rendered paste body
-- for ras, not tested
--
-- assumption:
-- table ip_alloc with field ip_addr

drop function trig_ip_overlap_iu() cascade;

create function trig_ip_overlap_iu() returns trigger as  $$
declare r int4;
begin
  select into r count(*)
  from ip_alloc a
  where a.ip_addr << new.ip_addr
     or a.ip_addr >> new.ip_addr
     or a.ip_addr =  new.ip_addr;
  if r>0 then
    raise exception 'Block will overlap'
  end if;
  return new;
end;
$$ language 'plpgsql';

drop  trigger trig_ip_overlap_aiu on ip_alloc;

create trigger trig_ip_overlap_aiu before insert or update on ip_alloc
for each row execute procedure trig_ip_overlay_iu();