python - 如何使用 BigQuery Python API 附加查询结果

标签 python api google-bigquery sql-insert

我找不到将查询结果附加到 BigQuery 中已存在且按小时分区的表的方法。 我只找到了这个解决方案:https://cloud.google.com/bigquery/docs/writing-results#writing_query_results .

job_config = bigquery.QueryJobConfig(destination=table_id)

sql = """SELECT * FROM table1 JOIN table2 ON table1.art_n=table2.artn"""

# Start the query, passing in the extra configuration.
query_job = client.query(sql, job_config=job_config)  # Make an API request.
query_job.result()  # Wait for the job to complete.

但是向 bigquery.QueryJobConfig 提供目标表会覆盖它,而且我没有发现 bigquery.QueryJobConfig 可以选择指定 if_exists 或其他东西。据我了解,我需要应用 job.insert 来查询结果,但我不明白如何。

我也没有找到任何好的建议,也许有人可以指点我?

以防万一,我的真实查询很大,我从一个单独的 JSON 文件加载它。

最佳答案

当您创建job_config 时,您需要将write_disposition 设置为WRITE_APPEND:

[..]
job_config = bigquery.QueryJobConfig(
    allow_large_results=True, 
    destination=table_id, 
    write_disposition='WRITE_APPEND'
)
[..]

here .

关于python - 如何使用 BigQuery Python API 附加查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63856773/

相关文章:

python - TKINTER 小部件的配置选项列表

Python,从一行中提取所有表达式的问题(仅提取第一个)

python - 如何使用 API 检查 Dropbox 帐户的同步状态?

api - 如何在 Laravel 中进行 JWT cookie 身份验证

java - 不应成为公共(public) API 一部分的公共(public)包/类

google-bigquery - 在 Google BigQuery 中创建一列 UUID

Python站点爬虫,用Scrapy保存文件

android - 如何从 Google Play Store API 中提取应用评级?

firebase - 使用 Firebase Export Collections to BigQuery 扩展将 Firestore 数据以表格格式存储在 BigQuery 中

python - 通过 Python 创建 Bigquery 表并加载数据