Skip to content

Instantly share code, notes, and snippets.

@jmbenedetto
Last active August 9, 2021 13:10
Show Gist options
  • Save jmbenedetto/d4edc3a47c5ff2301d698e5f91b973cd to your computer and use it in GitHub Desktop.
Save jmbenedetto/d4edc3a47c5ff2301d698e5f91b973cd to your computer and use it in GitHub Desktop.
#gbq
# Packages
import os
from google.cloud import bigquery
from google.oauth2 import service_account
# Parameters
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]='/Users/jmbenedetto/Library/Mobile Documents/com~apple~CloudDocs/#Formação/Dissertation/Research/02 Research v2/00 Base/key.json'
client = bigquery.Client(project=project_name)
dataset_ref = client.dataset(dataset_name)
load_config = bigquery.LoadJobConfig()
# Code
query = """
DELETE
FROM dataset_name.table_name
WHERE criteria;
"""
query_params = [
bigquery.ArrayQueryParameter("file", "STRING", file_source)
]
job_config = bigquery.QueryJobConfig()
job_config.query_parameters = query_params
query_job = client.query(
query,
# Location must match that of the dataset(s) referenced in the query.
location="EU",
job_config=job_config,
) # API request - starts the query
query_job.result(timeout=60.0)
assert query_job.state == "DONE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment