Python大查询错误:google.api_core.exceptions.BadRequest:400无法在带有DM



我正在编写Python代码,以使用BigQuery执行BigQuery sql Delete命令语句。Client.query.I正在获取无法在作业中设置目标表,DML语句异常。在此之前,我可以很好地使用选择状态,但在删除时会出错

下面是我使用的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))

关于如何绕过这个错误有什么想法吗?

当您使用DML删除特定表中的数据时,您不会将数据存储在另一个表(目标表(中。

目标表是可选的,write_disposition也是可选的。

您只需要运行DML查询。

正如错误所说:"无法在具有DML语句的作业中设置目标表">

最新更新