我正在编写Python代码,以便使用bigquery.Client.query执行BigQuery sql删除命令语句。我得到了Cannot set destination table in job with DML statements exception。在此之前,我可以很好地使用Selection语句,但在删除时会出错
下面是我使用的Python代码
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 = "ny.test.blue_test"
job_config = bigquery.QueryJobConfig(destination=table_id)
job_config.write_disposition = 'WRITE_APPEND'
sql = """
Delete
FROM
`ny.test.blue`
WHERE name = 'Beat';
"""
# 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))
有关于如何绕过这个错误的想法吗?
发布于 2020-03-06 08:57:11
由于您正在使用DML删除特定表中的数据,因此您没有将数据存储在另一个表(目标表)中。
目标表也是write_disposition,也是optional。
您只需要运行DML查询。
如错误所示:“无法在使用DML语句的作业中设置目标表”
https://stackoverflow.com/questions/60550574
复制相似问题