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:

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

nVector

posted on 18 Aug 18

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