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`'}.
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.
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 .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With