How to run a BigQuery SQL in Python

How to execute a BigQuery SQL Query using Python. How would I change this/ what do I have to add for it to run in Python?

First of all, You need to use the BigQuery Python client lib, then something like the below sample code should get you up and running:

\n\n
from google.cloud import bigquery\nclient = bigquery.Client(project='PROJECT_ID')\nquery = "SELECT...."\ndataset = client.dataset('dataset')\ntable = dataset.table(name='table')\njob = client.run_async_query('my-job', query)\njob.destination = table\njob.write_disposition= 'WRITE_TRUNCATE'\njob.begin()

nVector

posted on

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds