--
-- time_interval__new/2
--
create or replace function time_interval__new(
  new__start_date timestamp with time zone,
  new__end_date timestamp with time zone
) returns int4 as $$

DECLARE
       v_interval_id     time_intervals.interval_id%TYPE;
BEGIN
       select nextval('timespan_sequence') into v_interval_id from dual;

       insert into time_intervals 
            (interval_id, start_date, end_date)
       values
            (v_interval_id, new__start_date, new__end_date);
                
       return v_interval_id;

END;
$$ language plpgsql;