Skip to content

Commit

Permalink
Updated for day counting bug in _cnt
Browse files Browse the repository at this point in the history
  • Loading branch information
anagradova committed Sep 2, 2022
1 parent 15061c7 commit 7f0c2c4
Showing 1 changed file with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- migrate:up
-- FUNCTION: api.bin_devices_over_time(date, text, boolean, integer)

-- DROP FUNCTION IF EXISTS api.bin_devices_over_time(date, text, boolean, integer);

CREATE OR REPLACE FUNCTION api.bin_devices_over_time(
_start date,
_fscs_id text,
_direction boolean,
_days integer)
RETURNS integer[]
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
DECLARE
_new_start DATE;
_cnt INTEGER;
_full INTEGER[][]= '{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}';
--_full INTEGER[][];
_day_return INTEGER[];
BEGIN
_cnt := 0;
_new_start := _start;
WHILE _cnt < _days LOOP
IF _cnt != 0 THEN
IF _direction THEN
_new_start := _new_start::date + 1;
ELSE
_new_start := _new_start::date - 1;
END IF;
END IF;

raise notice 'Value: %', _new_start;

SELECT api.bin_devices_per_hour(_new_start, _fscs_id) INTO _day_return;

_full := array_cat(_full, _day_return);

_cnt := _cnt + 1;

END LOOP;
SELECT (_full)[2:_cnt +1] INTO _full;
RETURN _full;

END
$BODY$;

ALTER FUNCTION api.bin_devices_over_time(date, text, boolean, integer)
OWNER TO postgres;

GRANT EXECUTE ON FUNCTION api.bin_devices_over_time(date, text, boolean, integer) TO PUBLIC;

GRANT EXECUTE ON FUNCTION api.bin_devices_over_time(date, text, boolean, integer) TO postgres;

GRANT EXECUTE ON FUNCTION api.bin_devices_over_time(date, text, boolean, integer) TO web_anon;



-- migrate:down

0 comments on commit 7f0c2c4

Please sign in to comment.