来自 Apps 脚本的 DELETE 的 BigQuery 错误? [复制]

Posted

技术标签:

【中文标题】来自 Apps 脚本的 DELETE 的 BigQuery 错误? [复制]【英文标题】:BigQuery errs with DELETE from AppsScript? [duplicate] 【发布时间】:2020-03-04 14:42:43 【问题描述】:

我正在尝试从 AppsScript 发出 delete to BigQuery:

  var req = 
    // gotta place the where clause else BQ abends
    query: "delete from `" + projectId + "." + datasetId + "." + tableName + "` where 1=1;"
  ;

  var queryResults = BigQuery.Jobs.query(req,projectId);

唉,我收到以下错误:

GoogleJsonResponseException: API call to bigquery.jobs.query failed with error: 1.1 - 1.53: Unrecognized token delete. [Try using standard SQL (https://cloud.google.com/bigquery/docs/reference/standard-sql/enabling-standard-sql)] (line 61, file "Code")

显然,这里的问题不在于“标准”语法,而是看起来好像 API 正在预先验证 SQL 语句;说验证器可能没有意识到现在支持deletes。

那么将使用什么机制从 AppsScript 中删除表数据?

【问题讨论】:

很明显怎么这么明显? 这能回答你的问题吗? Insert data into BigQuery from a Google Script : Encountered "" @TheMaster,抱歉,文档中提到的 BQ SQL 语法支持 delete 语法。 @TheMaster,您的参考确实有效!谢谢,想要答案吗? 太棒了!但不是。因为它是完全重复的。没有什么我可以补充的。不过,您可以投票赞成我的其他答案:) 【参考方案1】:

您需要将 #standardSQL 添加到您的 sql 中才能从应用脚本运行 BigQuery

var req = 
    // gotta place the where clause else BQ abends
    query: "#standardSQL \n delete from `" + projectId + "." + datasetId + "." + tableName + "` where 1=1;"
  ;

  var queryResults = BigQuery.Jobs.query(req,projectId);

\n 在技术上不是必需的,它是我的格式偏好。当/如果您在 BigQuery 的“查询历史记录”中查找调用时,它将在单独的行中显示命令

【讨论】:

以上是关于来自 Apps 脚本的 DELETE 的 BigQuery 错误? [复制]的主要内容,如果未能解决你的问题,请参考以下文章