gpt4 book ai didi

google-bigquery - BigQuery : How to overwrite a table with bigquery. Client()。copy_table方法

转载 作者:行者123 更新时间:2023-12-04 16:50:34 34 4
gpt4 key购买 nike

这是我用作https://cloud.google.com/bigquery/docs/managing-tables#bigquery-copy-table-python的引用的代码:

source_dataset = client.dataset('samples', project='bigquery-public-data')
source_table_ref = source_dataset.table('shakespeare')

# dataset_id = 'my_dataset'
dest_table_ref = client.dataset(dataset_id).table('destination_table')

job = client.copy_table(
source_table_ref,
dest_table_ref,
# Location must match that of the source and destination tables.
location='US') # API request

job.result() # Waits for job to complete.

在我的情况下,目标表存在,并且出现此错误:
Already Exists

如何使用此copy_table方法覆盖?在bq命令行中,我可以使用-f选项。所以我正在寻找相同的标志。

最佳答案

您需要像这样将作业配置传递给请求:

job_config = bigquery.CopyJobConfig()
job_config.write_disposition = "WRITE_TRUNCATE"
job = client.copy_table(
source_table_ref,
dest_table_ref,
location='US',
job_config=job_config) # API request

此处有更多文档: https://googleapis.github.io/google-cloud-python/latest/bigquery/generated/google.cloud.bigquery.client.Client.copy_table.html

关于google-bigquery - BigQuery : How to overwrite a table with bigquery. Client()。copy_table方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52775325/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com