简体   繁体   中英

Google Apps Script for BigQuery (Standard SQL) - NaN

Facing some issues with my apps script that seems to run, but only selected lines and i'm not sure why. Was wondering if it could be an issue with standard SQL and some parameters. This is my code

function runQuery() {
  var configuration = {
    query: {
    useQueryCache: false,
    destinationTable: {
          projectId: "projectA",
          datasetId: "datasetA",
          tableId: "NewTable"
        },
    writeDisposition: "WRITE_TRUNCATE",
    createDisposition: "CREATE_IF_NEEDED",
    allowLargeResults: true,
    useLegacySql: false,
    query: "WITH a AS" + 
      "(SELECT Date, Month, Quarter, Week, Year FROM Dataset.Table1`)," + 
      "b AS "+
      "(SELECT * FROM `Dataset.Table2`)," +
      "c AS "+
      "(SELECT * FROM `Dataset.Table3`) " + 
      "SELECT Date, Month, Quarter, Week, Year, .... FROM a" + 
      "LEFT JOIN b ON a.x = b.x LEFT JOIN c ON a.x = c.x"
    }
  };

  var job = {
    configuration: configuration
  };

  var jobResult = BigQuery.Jobs.insert(job, "projectA");
  Logger.log(jobResult);
}

(Have changed the variables and table names to blank out the contents, but the general structure of the code has been shown)

The SQL code itself works on BigQuery, so the issue is not with an error in the query.

When I attempt to run this, the log on BigQuery seems to show that the code executed is only the last 2 lines of the code, with a NaN in front

NaNSELECT Date, Month, Quarter, Week, Year, .... FROM a LEFT JOIN b ON a.x = b.x LEFT JOIN c ON a.x = c.x

Appreciate any help on this. Thanks

I think, you are missing back-tick in below line

  "(SELECT Date, Month, Quarter, Week, Year FROM Dataset.Table1`)," +   

It should be

  "(SELECT Date, Month, Quarter, Week, Year FROM `Dataset.Table1`)," +  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM