【发布时间】:2020-03-24 18:14:05
【问题描述】:
我正在编写一个将查询结果写入 BQ 表的 python 脚本。第一次运行脚本后,它总是出错,并出现以下错误:google.api_core.exceptions.Conflict: 409 Already Exists: Table project-id.dataset-id。我不明白为什么每次我运行脚本时它都试图创建一个表。我是否指定了任何具体参数?
这是来自谷歌的文档。我以此为例,并认为当前表已经创建。我在哪里阻止 api 创建同一个表?
from google.cloud import bigquery
# TODO(developer): Construct a BigQuery client object.
client = bigquery.Client()
# TODO(developer): Set table_id to the ID of the destination table.
table_id = "your-project.your_dataset.your_table_name"
job_config = bigquery.QueryJobConfig(destination=table_id)
sql = """
SELECT corpus
FROM `bigquery-public-data.samples.shakespeare`
GROUP BY corpus;
"""
# 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.
print("Query results loaded to the table {}".format(table_id))
【问题讨论】:
标签: python google-api google-bigquery