Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create function start_stop_record() returns vts_position as
- $$
- declare
- sp record;
- last_was_zero integer := -1;
- records varchar(4000);
- begin
- for sp in select * from vts_position order by rawid loop
- if sp.speed =0 then
- if last_was_zero = -1 then
- last_was_zero = 1;
- elsif last_was_zero = 1 then last_was_zero =1;
- elsif last_was_zero = 0 then select ROW(sp.rawid)::vts_position; last_was_zero = 1; end if;
- elsif sp.speed > 0 then
- if last_was_zero =-1 then
- select ROW(sp.rawid)::vts_position; last_was_zero = 0;
- elsif last_was_zero = 0 then
- last_was_zero=0;
- elsif last_was_zero = 1 then
- select ROW(sp.rawid)::vts_position; last_was_zero = 0;
- end if;
- else raise notice 'exception where rawid %',sp.rawid; end if;
- end loop;
- end;
- $$
- language plpgsql;
Add Comment
Please, Sign In to add comment