
drop function time_hole();
create function time_hole() returns setof record as '
declare
	v_fr		record;
	v_to		record;
	max_hole	interval;
begin
	max_hole := 0;
	--select * into v_fr from httplog order by hitDateTime asc;
	select hitDateTime, TimeSpent into v_fr from httplog order by hitDateTime asc;
	--for v_to in select * from httplog order by hitDateTime asc loop
	for v_to in select hitDateTime, TimeSpent from httplog order by hitDateTime asc loop
		if max_hole < v_to.hitDateTime - v_fr.hitDateTime then
			max_hole := v_to.hitDateTime - v_fr.hitDateTime;
			v_fr.TimeSpent := max_hole;
			return next v_fr;
		end if;
		v_fr.hitDateTime := v_to.hitDateTime;
		--v_fr := v_to;
	end loop;
	return;
end;
' language 'PLpgSQL';

select hitdatetime as "From", hitdatetime+hole as "To", hole as "Hole" from time_hole() as (hitDateTime timestamp with time zone, Hole interval) order by Hole desc limit 1;


