Define BigQuery table location in Google Apps Script

358 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 best solutions below

0
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
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`