splexamples.sql 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. drop function check_open(stock_bar, float);
  2. create function check_open(tsrow stock_bar, ARG_VAL float) returning stock_bar;
  3. -- Use the argument in some way
  4. if tsrow.high > ARG_VAL then
  5. let tsrow.high = -1;
  6. end if
  7. return row(tsrow.timestamp, tsrow.high, tsrow.low, tsrow.final, tsrow.vol)::stock_bar;
  8. end function;
  9. --------------------------------------------------------------------------------
  10. drop procedure spl_test();
  11. create procedure spl_test()
  12. define id integer;
  13. define name lvarchar;
  14. define var stock_bar;
  15. define ts timeseries(stock_bar);
  16. begin work;
  17. foreach select stock_id, stock_name, stock_data into id, name, ts from daily_stocks
  18. foreach execute function transpose(
  19. ts::timeseries(stock_bar),
  20. '2011-01-03 00:00:00.00000'::datetime year to fraction(5),
  21. '2011-04-10 00:00:00.00000'::datetime year to fraction(5))
  22. into var
  23. execute function check_open(var, 600) into var;
  24. update daily_stocks set stock_data = PutElemNoDups(stock_data, var);
  25. end foreach
  26. end foreach
  27. commit work;
  28. end procedure;