Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BigQuery invalid table name error when using Standard SQL in BigQuery API's

I am trying query the table and store the result in another BigQuery table using python BigQuery API. But when I use standard SQL in query part it throws invalid table name error. How to use standard SQL in BigQuery API? I am using airflow BigQuery hoooks

'configuration': {
        'query': {
            'destinationTable': {
                'tableId': u 'our_table_name',
                'datasetId': 'our_dataset_id',
                'projectId': 'our_project_id'
            },
            'useLegacySql': False,
            'allowLargeResults': True,
            'writeDisposition': 'WRITE_TRUNCATE',
            'query': u'SELECT * FROM `projectID.datasetId.tablename`',
            
        }
    }
Exception: BigQuery job failed. Final error was: {u'reason': u'invalid', u'message': u'Invalid table name: `projectId:datasetId.tableId`', u'location': u'`projectId:datasetId.tableId`'}.
like image 561
MJK Avatar asked Mar 22 '17 04:03

MJK


People also ask

Does BigQuery use standard SQL?

BigQuery supports the Google Standard SQL dialect, but a legacy SQL dialect is also available. If you are new to BigQuery, you should use Google Standard SQL as it supports the broadest range of functionality. For example, features such as DDL and DML statements are only supported using Google Standard SQL.

What is difference between standard SQL and legacy SQL?

The main differences Additionally, the standard dialect has a smaller range of valid values of type TIMESTAMP compared to legacy SQL. The former only accepts values in the range in between 0001-01-01 00:00:00.000000 and 9999-12-31 23:59:59.999999 .

Is table name case sensitive in BigQuery?

If you have a table name that is longer than 32 characters, it is recommended that you create a table view. Google BigQuery is not case sensitive, so all names default to lowercase.

Does BigQuery support ANSI SQL?

Google BigQuery supports ANSI SQL and has all the supported functions available like analytical, window, aggregation, and many more. SQL Server also supports ANSI SQL and has all the features of SQL available to the users to perform analytics over data.


1 Answers

The error is confusing, but the root cause is that this query was interpreted as Legacy SQL, not as Standard SQL. In JSON (unlike, say, in Python), boolean literals true and false must be lowercase, per JSON standard Section 3:

A JSON value MUST be an object, array, number, or string, or one of
the following three literal names:

  false null true

The literal names MUST be lowercase. No other literal names are
allowed.

So if you change

        `'useLegacySql': False,`

to

        `'useLegacySql': false,`

it should work

like image 189
Mosha Pasumansky Avatar answered Sep 20 '22 16:09

Mosha Pasumansky