我找不到将查询结果附加到 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/