Get a Big Query script to output a table

两盒软妹~` 提交于 2021-02-11 15:14:05

问题


I am using the new scripting feature of Big Query to declare a variable and then am using that variable in a standard SQL query.

The structure of the query is :

DECLARE {name of variable} {data type};

SET {name of variable} = {Value}'

(A SQL QUERY THEN FOLLOWS USING THE ABOVE VARIABLE)

I understand that this is now a script a no longer a typical query, and thus when I run it, it runs as a sequence of executable tasks. But is there anyway in the script to explicitly state that I only want to output the resulting table of the SQL query as opposed to both the result of declaring the variable and SQL query?

What BQ Outputs


回答1:


Depending on how you "capture" the output, if you are sending a query from Python/Java/CLI, then the last SELECT statement in script is the only output that you receive with the API.

Please also note that each "output" that you see come with a cost/bytes-billed, which is another reason for them to be visible at all time.

Update: If you need to capture the output of SELECT statement to a table, depending on your intention, you may use:

CREATE OR REPLACE TABLE <your_destination_table> AS SELECT ...

or

INSERT INTO TABLE <your_destination_table> SELECT ...


来源:https://stackoverflow.com/questions/58713210/get-a-big-query-script-to-output-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!