python
delete data from table
# 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"
Was this helpful?
Similar Posts
- Django: How to Delete All Rows from a Table
- update data from table
- Add column to existing table with default value SQLAlchemy
- Create table model using SQLAlchemy
- SQLAlchemy query to get distinct records from table
- Python - String ,remove,delete,replace,extract numbers from string
- Pandas - Delete,Remove,Drop, column from pandas DataFrame