Define BigQuery table location in Google Apps Script

343 views Asked by At

I am trying to read data form BigQuery table in Google Apps Script. Target table is located in EU region, but US is requested by default from script.

Code

  var request = {
    query: 'SELECT * FROM `table-name`'
  };
  var queryResults = BigQuery.Jobs.query(request, projectId);

Error:

GoogleJsonResponseException: API call to bigquery.jobs.query failed with error: Not found: Dataset <dataset-name.table-name> was not found in location US

2

There are 2 answers

0
Olga On

Quotes `` was a problem, table name should be without without quotes :

 var projectId = "project_id"
 var request = {    
        query: 'SELECT * FROM data_set.table ',
      };
 var queryResults = BigQuery.Jobs.query(request, projectId);
2
Yun Zhang On

Your query is expected to be automatically routed to where the data is, if you have the right dataset to qualify the table name, e.g.:

SELECT * FROM `myDatasetInEu.table-name`