Is there a way to fetch a query result inside a stored procedure and then iterate over the rows in BigQuery? Having something like a cursor with each row.
This is my stored procedure, it takes 6 parameters and I take those parameters from a table. I would like to call the procedure X times (X being the number of rows of my input table). So something like :
FOR device_id, nb_measures, delta_t_min, delta_t_last_rec, date_cr, frame IN (SELECT device_id, nb_measures, delta_t_min, delta_t_last_rec, date_cr, frame FROM my_project.my_dataset.my_table
)
BEGIN
DECLARE count INT64 DEFAULT 0;
SET temp_list = [];
WHILE count < nb_measures DO
SET temperature = `bdz-dts-datascience-dev.fonctions.hexStringToInt`(frame, 5 + count, 1, 0, 8);
IF temperature != 127 THEN
IF count = 0 THEN
SET measure_time = TIMESTAMP_SUB(date_cr, INTERVAL delta_t_last_rec MINUTE);
ELSE
SET measure_time = TIMESTAMP_SUB(date_cr, INTERVAL delta_t_last_rec + count * delta_t_min MINUTE);
END IF;
INSERT `20191218_temperature_repeteurs.step_2`(device_id, measure_time, temperature)
VALUES(measure_time, temperature);
END IF;
END WHILE;
END;
Or on the other hand is there a way to execute a stored procedure inside a SELECT
query to iterate through the results ?
SELECT
device_id, nb_mesures, delta_t_min, delta_t_last_rec, date_cr, frame
CALL `my-dataset.my_procedure`(device_id, nb_mesures, delta_t_min, delta_t_last_rec, date_cr, frame)
FROM `my_project.my_dataset.my_table`)