我正在尝试使用 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/