google-apps-script - 如何修复错误 'API call to bigquery.jobs.query failed with error: Encountered " "FROM" "from "“at .... 期待 : ")"'

标签 google-apps-script google-bigquery google-sheets-api

我正在尝试使用 appscript 中的查询字符串(附加在代码中)运行 bigquery api 调用;查询在 bigquery UI 中运行得非常好

我尝试了以下方法但没有成功:
1. 在查询字符串中的orders.creation_date中包含括号
2. 将订单替换为实际表,即 [my-project:theservices.theservice_order_item]

/**
 * Runs a BigQuery query and logs the results in a spreadsheet.
 */
function runQuery() {

  var projectId = 'my-project';

  var request = {
    query:  
    "SELECT  extract(date from orders.creation_date) as the_date \n FROM [my-project:theservices.theservice_order_item] AS orders LIMIT 10;"   
  }; 

};

以下是我收到的错误:
对 bigquery.jobs.query 的 API 调用失败并出现错误:在第 1 行第 22 列遇到“"FROM""from ""。期望:")"...(第 23 行,文件“Code”)

最佳答案

引用App Script BigQuery Standard SQL insert or update statement :

You need to set the useLegacySql flag/parameter to false, to indicate that you want to use standard SQL, like so:

var job = {
configuration: {
  query: {
    query: 'SELECT ....',
    useLegacySql: false
    }

此外,当表看起来像这样时 - 那就是#legacySQL:

FROM [my-project:theservices.theservice_order_item]

在#standardSQL 中,表应包含在波形符“`”中并带有“.”。项目和数据集名称之间:

FROM `my-project.theservices.theservice_order_item`

关于google-apps-script - 如何修复错误 'API call to bigquery.jobs.query failed with error: Encountered " "FROM" "from "“at .... 期待 : ")"',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56372018/

相关文章:

google-apps-script - 与 Google Apps 脚本一起使用的 Caja 版本

google-apps-script - 如何通过apps脚本从googlesheet获取特定范围的行数据

google-apps-script - Google 应用电子表格父文件夹 ID

python - 如何将 "array of strings"添加为 BigQuery 的架构值

javascript - 在 Google App 脚本中返回多个参数值

python-3.x - Pygsheets update_cells() 不工作

javascript - Google Apps 脚本 map 教程错误

google-bigquery - BigQuery 查询列数不可预测的表

python - 如何列出 Google Big Query 中所有数据集中所有表的大小

google-sheets-api - 在给定工作表 ID 但不给定工作表标题的情况下,如何才能仅获取使用 Spreadsheets.get 填充的行?