--
-- time_interval__eq/2
--
create or replace function time_interval__eq(
  integer,
  integer
) returns bool as $$
	--  return boolean
declare
       eq__interval_1_id   alias for $1;
       eq__interval_2_id   alias for $2;
       interval_1_row time_intervals%ROWTYPE;
       interval_2_row time_intervals%ROWTYPE;
begin
       select * into interval_1_row
       from   time_intervals
       where  interval_id = eq__interval_1_id;

       select * into interval_2_row
       from   time_intervals
       where  interval_id = eq__interval_2_id;

       if interval_1_row.start_date = interval_2_row.start_date and 
          interval_1_row.end_date = interval_2_row.end_date 
       then
            return true;
       else
            return false;
       end if;

end;$$ language plpgsql;