【问题标题】:How to fix the error 'API call to bigquery.jobs.query failed with error: Encountered " "FROM" "from "" at .... Was expecting: ")"'如何修复错误“对 bigquery.jobs.query 的 API 调用失败并出现错误:在 .... 遇到““FROM”“来自“”。期待:“)”'
【发布时间】:2019-10-15 17:48:20
【问题描述】:

我正在尝试使用 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”。期待:“)”...(第 23 行,文件“代码”)

【问题讨论】:

  • 如果删除\n会发生什么?
  • 仍然收到以下错误:对 bigquery.jobs.query 的 API 调用失败并出现错误:在第 1 行第 22 列遇到“来自”“FROM”。期待:“)”.. .
  • 好的。此查询不在 UI 中运行。它混合了#standardSQL 和#legacySQL。 “查询在 bigquery UI 中运行得非常好” - 不。
  • 是的,在 web ui 上,我使用以下代码可以正常工作:SELECT EXTRACT(date FROM orders.creation_date) FROM data-analytics-related.theservices.theservice_order_item AS orders
  • 我在这个 data-analytics-related.theservices.theservice_order_item 上使用了 sting 文字

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


【解决方案1】:

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

您需要将 useLegacySql 标志/参数设置为 false,表示您要使用标准 SQL,如下所示:

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

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

FROM [my-project:theservices.theservice_order_item]

在#standardSQL 中,表应该用波浪号“`”括起来并带有一个“.”。在项目和数据集名称之间:

FROM `my-project.theservices.theservice_order_item`

【讨论】:

  • 插入 useLegacySql: false 工作......非常感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-15
  • 2019-11-28
  • 1970-01-01
  • 2022-10-17
  • 2020-12-29
  • 1970-01-01
  • 2019-08-23
相关资源
最近更新 更多