How to use App script to run a google big query and save it as a new table which can we reused?

前端 未结 1 1495
情书的邮戳
情书的邮戳 2021-01-29 00:55

How to use app script to run a google big query and save the results in a new table in the same project folder on google big query

相关标签:
1条回答
  • 2021-01-29 01:29

    It will look like this:

    function saveQueryToTable() {
      var projectId = 'your project';
      var datasetId = 'your dataset';
      var tableId = 'your table';
      var job = {
        configuration: {
          query: {
            query: 'SELECT TOP(word, 300) AS word, COUNT(*) AS word_count' +
                   'FROM publicdata:samples.shakespeare' +
                   'WHERE LENGTH(word) > 10;',
            destinationTable: {
              projectId: projectId,
              datasetId: datasetId,
              tableId: tableId
            }
          }
        }
      };
    
      var queryResults = BigQuery.Jobs.insert(job, projectId);
      Logger.log(queryResults.status);
    }
    

    More examples here.

    0 讨论(0)
提交回复
热议问题