首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Python大查询错误: google.api_core.exceptions.BadRequest: 400无法在使用dml语句的作业中设置目标表

Python大查询错误: google.api_core.exceptions.BadRequest: 400无法在使用dml语句的作业中设置目标表
EN

Stack Overflow用户
提问于 2020-03-06 01:03:10
回答 1查看 792关注 0票数 0

我正在编写Python代码,以便使用bigquery.Client.query执行BigQuery sql删除命令语句。我得到了Cannot set destination table in job with DML statements exception。在此之前,我可以很好地使用Selection语句,但在删除时会出错

下面是我使用的Python代码

代码语言:javascript
运行
复制
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))

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

EN

回答 1

Stack Overflow用户

发布于 2020-03-06 08:57:11

由于您正在使用DML删除特定表中的数据,因此您没有将数据存储在另一个表(目标表)中。

目标表也是write_disposition,也是optional

您只需要运行DML查询。

如错误所示:“无法在使用DML语句的作业中设置目标表”

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60550574

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档