Question

We have tables stored as :

  • ga_sessions_20131201
  • ga_sessions_20131202
  • ...
  • ga_sessions_20131207

Running a simple query like the following should be valid judging from the documentation, but fails.

    SELECT 
     SUM(totals.visits) AS visits,
     SUM(totals.bounces) AS bounces
    FROM 
      (TABLE_DATE_RANGE(<projectId>:<dataSetId>.ga_sessions_, 
                    TIMESTAMP('2013-12-01'), 
                    TIMESTAMP('2013-12-07'))) 

Is there an issue with TABLE_DATE_RANGE when the prefix contains '_', or the project contains '-' ? Am I supposed to be escaping any characters? I am testing date ranges on the BQ web interface currently, but will be using the API as well.

JobId: nmodal-big-query-1:job_FygE9ZzY9Fxi7UUfdQxS6RfuqIA

Was it helpful?

Solution

If you've got non-alphanumeric chars in your dataset, table, or project it, you'll need to use the bigquery sql quotes ([]), as in

 SELECT 
   SUM(totals.visits) AS visits,
   SUM(totals.bounces) AS bounces
  FROM 
    (TABLE_DATE_RANGE([<projectId>:<dataSetId>.ga_sessions_], 
                  TIMESTAMP('2013-12-01'), 
                  TIMESTAMP('2013-12-07'))) 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top