【发布时间】:2019-12-18 16:35:27
【问题描述】:
有没有办法在存储过程中获取查询结果,然后遍历 BigQuery 中的行?每行都有一个光标之类的东西。
这是我的存储过程,它需要 6 个参数,我从表中获取这些参数。我想调用该过程 X 次(X 是我的输入表的行数)。所以像:
对于 device_id、nb_measures、delta_t_min、delta_t_last_rec、date_cr、帧 IN(选择 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;
或者另一方面,有没有办法在 SELECT 查询中执行存储过程来遍历结果?
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`)
【问题讨论】:
标签: stored-procedures google-bigquery