如何使用Python删除或清空BigQuery中的表 [英] How to delete or empty a table that is in BigQuery using Python
问题描述
我正在将一个JSON文件上传到BigQuery,并希望每周都这样做。不过,我希望表格被删除或清空表格。我尝试截断,但一直无法让它工作。如果它在重新上传之前没有被移除,他只会添加数据,然后会有很多重复的信息。谢谢您的帮助。
您无法直接截断。 > - 将参数替换为 bq cli加载作业具有所需的效果,清除现有数据。使用API模式时也称为WRITE_TRUNCATE。
bq load --autodetect --replace --source_format = NEWLINE_DELIMITED_JSON mydataset.mytable gs://mybucket/mydata.json
I am uploading a JSON file to BigQuery and want to do this weekly. However I want the table to be deleted or have the table emptied. I tried truncating but haven't been able to get that to work. If it isn't removed before re-uploading he data is just added in and then there will be a lot of duplicated info. Thanks for the help.
You can't truncate directly.
The --replace parameter to a bq cli load job has the effect you want, clearing out the existing data. Also referred to as WRITE_TRUNCATE when using API mode.
bq load --autodetect --replace --source_format=NEWLINE_DELIMITED_JSON mydataset.mytable gs://mybucket/mydata.json
这篇关于如何使用Python删除或清空BigQuery中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!