I am trying to query my BigQuery database using Python but every time I run this code I get an error saying "No query found" even though the query works fine on Google Cloud Console.
Note: myfilepath.json and my-project-id are valid values in the code I have.
def explicit():
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "myfilepath.json"
credentials = GoogleCredentials.get_application_default()
bigquery_service = build('bigquery', 'v2', credentials=credentials)
query_request = bigquery_service.jobs()
query_data = {
'query': ('#standardSQL SELECT * FROM `SentimentAnalysis.testdataset`')
}
query_response = query_request.query(
projectId='my-project-id',
body=query_data).execute()
print(query_response)
explicit()
The error I get every time is:
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/bigquery/v2/projects/my-project-id/queries?alt=json returned "1.58 - 1.58: No query found.">
SentimentAnalysis.testdataset[Try using standard SQL]#which made it a comment. do now you should just set respective property to standardSQL. Something like -query_request.use_legacy_sql = False