根据Google BigQuery中的查询结果创建一个表格 [英] Create a table from query results in Google BigQuery

查看:97
本文介绍了根据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.

我们要模拟:

We want to simulate:


SELEC ... INTO ...from 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆