Guest User

Untitled

a guest
May 17th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. create function start_stop_record() returns vts_position as
  2. $$
  3. declare
  4. sp record;
  5. last_was_zero integer := -1;
  6. records varchar(4000);
  7. begin
  8. for sp in select * from vts_position order by rawid loop
  9. if sp.speed =0 then
  10. if last_was_zero = -1 then
  11. last_was_zero = 1;
  12. elsif last_was_zero = 1 then last_was_zero =1;
  13. elsif last_was_zero = 0 then select ROW(sp.rawid)::vts_position; last_was_zero = 1; end if;
  14. elsif sp.speed > 0 then
  15. if last_was_zero =-1 then
  16. select ROW(sp.rawid)::vts_position; last_was_zero = 0;
  17. elsif last_was_zero = 0 then
  18. last_was_zero=0;
  19. elsif last_was_zero = 1 then
  20. select ROW(sp.rawid)::vts_position; last_was_zero = 0;
  21. end if;
  22. else raise notice 'exception where rawid %',sp.rawid; end if;
  23. end loop;
  24. end;
  25. $$
  26. language plpgsql;
Add Comment
Please, Sign In to add comment