Get data from Google BigQuery by app script

2019-08-13 12:43发布

I make query to Google BigQuery, and it works in console, but fail when I try the same in google app script here is the code:

in console runs normal:

SELECT title FROM [bigquery-public-data:samples.wikipedia] where title contains 'olimpic' LIMIT 100

in app script it runs with error:

Encountered " "-" "- "" at line 1, column 27. Was expecting: 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)
}

What I do wrong?

1条回答
唯我独甜
2楼-- · 2019-08-13 12:46

You're missing the square brackets around the project:dataset.table name. It should be:

'SELECT title FROM [bigquery-public-data:samples.wikipedia] where title contains "olimpic" LIMIT 100'

Note: try to avoid using legacy SQL. I'd do this instead (use standard SQL):

var configuration = {
    "query": {
    "useQueryCache": false,
    "useLegacySql": false,
    "query": 'SELECT title FROM `bigquery-public-data.samples.wikipedia` where title like "%olimpic%" LIMIT 100'
    }   };
查看更多
登录 后发表回答