根据 Google BigQuery 中的查询结果创建表 [英] Create a table from query results in Google BigQuery
问题描述
我们通过 Python API 使用 Google BigQuery.我将如何从查询结果创建一个表(新的或覆盖旧的)?我查看了查询文档,但我觉得它没有用.
We're using Google BigQuery via the Python API. How would I create a table (new one or overwrite old one) from query results? I reviewed the query documentation, but I didn't find it useful.
我们要模拟:
选择 ... INTO ..." 来自 ANSI SQL.
"SELEC ... INTO ..." from ANSI SQL.
推荐答案
您可以通过在查询中指定目标表来实现此目的.您需要使用 Jobs.insert
API 而不是 Jobs.query
调用,并且您应该指定 writeDisposition=WRITE_APPEND
并填写目标表.
You can do this by specifying a destination table in the query. You would need to use the Jobs.insert
API rather than the Jobs.query
call, and you should specify writeDisposition=WRITE_APPEND
and fill out the destination table.
如果您使用原始 API,则配置如下所示.如果您使用 Python,Python 客户端应该提供对这些相同字段的访问器:
Here is what the configuration would look like, if you were using the raw API. If you're using Python, the Python client should give accessors to these same fields:
"configuration": {
"query": {
"query": "select count(*) from foo.bar",
"destinationTable": {
"projectId": "my_project",
"datasetId": "my_dataset",
"tableId": "my_table"
},
"createDisposition": "CREATE_IF_NEEDED",
"writeDisposition": "WRITE_APPEND",
}
}
这篇关于根据 Google BigQuery 中的查询结果创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!