-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated for day counting bug in _cnt
- Loading branch information
1 parent
15061c7
commit 7f0c2c4
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
imls-backend/db/migrations/20220902170318_update_bin_devices_over_time.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|