我向Google BigQuery查询,它在控制台中运行,但是当我在谷歌应用程序脚本中尝试相同时失败的代码是:
控制台中的运行正常:
SELECT title FROM [bigquery-public-data:samples.wikipedia] where title contains 'olimpic' LIMIT 100
在应用程序脚本中运行错误:
在第1行第27栏遇到“” - “” - “”。期待:EOF
function runQuery() {
var projectId = 'cool-reality-177704';
var request = {
query: 'SELECT title FROM bigquery-public-data:samples.wikipedia where title contains "olimpic" LIMIT 100'
};
var queryResults = BigQuery.Jobs.query(request, projectId);
var jobId = queryResults.jobReference.jobId;
Logger.log(queryResults)
}
我做错了什么?
答案 0 :(得分:2)
您错过了project:dataset.table
名称周围的方括号。它应该是:
'SELECT title FROM [bigquery-public-data:samples.wikipedia] where title contains "olimpic" LIMIT 100'
注意:尽量避免使用旧版SQL。我会这样做(使用标准SQL):
var configuration = {
"query": {
"useQueryCache": false,
"useLegacySql": false,
"query": 'SELECT title FROM `bigquery-public-data.samples.wikipedia` where title like "%olimpic%" LIMIT 100'
} };