Google BigQuery:一个查询中多个表的删除语句

Google BigQuery: Delete Statement for several tables in one query

是否可以在一个查询中删除多个表中的行?

像这样:

delete FROM project.dataset.table1, project.dataset.table2, project.dataset.table3
where id not in 
(
    select distinct id from project.dataset.table4
)

有办法吗??

DML 通常在一个 table 上。使用 MERGE 语句可以对单个 table 执行许多操作。

所有三个删除都需要单独执行。

bq 实用程序可以处理多个查询语句,如果它们作为单个 sql 文件传递​​。

mydeletefile.sql

delete FROM dataset.table1 where id not in 
(select distinct id from dataset.table4);

delete FROM dataset.table2 where id not in 
(select distinct id from dataset.table4);

delete FROM dataset.table3 where id not in 
(select distinct id from dataset.table4);

运行 bq

cat mydeletefile.sql | bq query --use_legacy_sql=false

(假设 bq init 已经 运行 并且项目已配置)

由于@T0ny1234 评论需要检查 FK 约束是否违反。
但底线 - 多个 table 行删除不是通常考虑的概念,在任何 SQL 实现中都没有看到 很高兴得到纠正