[英]Storing results of a stored procedure in a Google Big Query table
Here is a link to the question I asked earlier.这是我之前提出的问题的链接。 The accepted answer works perfectly.
接受的答案完美无缺。
But this stored procedure processes 2 statements and after running this procedure I have to click on View Results of the second statement to see the result in Google Big Query.但是这个存储过程处理 2 个语句,运行这个过程后我必须单击第二个语句的查看结果才能在 Google Big Query 中查看结果。 Is there a way to save the results in some table automatically using the 'Query Settings' in Google Big Query and specifying the name of the table I want to store the results in?
有没有一种方法可以使用 Google Big Query 中的“查询设置”自动将结果保存在某个表中,并指定我要存储结果的表的名称?
You cannot set a destination table for a script (or for call a procedure), instead, you can convert your SELECT
statement into CREATE TABLE ... AS SELECT
, for example:您不能为脚本(或调用过程)设置目标表,相反,您可以将
SELECT
语句转换为CREATE TABLE ... AS SELECT
,例如:
SELECT 1 x;
=>
CREATE TABLE myDataset.myTable
AS SELECT 1 x;
You can define a string parameter for your procedure.您可以为您的过程定义一个字符串参数。 Then use this parameter in the dynamic query to write the results to the table.
然后在动态查询中使用这个参数将结果写入表中。
CREATE OR REPLACE PROCEDURE `my_dataset.my_procedure`(destination_table STRING)
BEGIN
CREATE TEMP TABLE tmp AS SELECT 1 x;
EXECUTE IMMEDIATE (
FORMAT("CREATE OR REPLACE TABLE `%s` AS SELECT * FROM tmp", destination_table));
END
Now you can provide a table name and call this procedure to write the results to the table.现在您可以提供表名并调用此过程将结果写入表中。
CALL `my_dataset.my_procedure`("my_dataset.my_table");
SELECT * FROM `my_dataset.my_table`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.