简体   繁体   English

如何从 Google App Script 执行 Big Query 表的简单查询

[英]How to execute simple query of Big Query table from Google App Script

I'm having trouble figuring out how to execute a simple delete query against a Big Query Table from an app script function. The query works when executing from the Big Query console.我无法弄清楚如何从应用程序脚本 function 对大查询表执行简单的删除查询。从大查询控制台执行时查询有效。 The error is coming back as: Unrecognized name: for the timestamp value I'm trying to pass in to string query.错误返回为:无法识别的名称:对于我试图传递给字符串查询的时间戳值。

The BigQuery api is loaded into app script as I can execute a simple select query with no parameter. BigQuery api 已加载到应用程序脚本中,因为我可以执行不带参数的简单 select 查询。

function RemoveRoles()
{
   var sheet = SpreadsheetApp.getActive().getSheetByName("Config");
   var value = sheet.getRange(2,2).getValue();

  const projectId = 'xxxxx-346316';

  const request = {
       
    query: 'delete FROM `xxxxx-346316.Feedback.Role`  where `Time` < `' + value + '`;', 
    useLegacySql: false
  };
  let queryResults = BigQuery.Jobs.query(request, projectId);
  const jobId = queryResults.jobReference.jobId;

  // Check on status of the Query Job.
  let sleepTimeMs = 500;
  while (!queryResults.jobComplete) {
    Utilities.sleep(sleepTimeMs);
    sleepTimeMs *= 2;
    queryResults = BigQuery.Jobs.getQueryResults(projectId, jobId);



}
}

GoogleJsonResponseException: API call to bigquery.jobs.query failed with error: Unrecognized name: 2022-03-04 18:28:00 at [1:58] GoogleJsonResponseException:API 调用 bigquery.jobs.query 失败,出现错误:无法识别的名称: 2022-03-04 18:28:00 [1:58]

replace代替

  const request = {
       
    query: 'delete FROM `xxxxx-346316.Feedback.Role`  where `Time` < `' + value + '`;', 
    useLegacySql: false
  };    

with

  const request = {
       
    query: 'delete FROM `xxxxx-346316.Feedback.Role`  where `Time` < "' + value + '";', 
    useLegacySql: false
  };    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM