14mble
14mble

Reputation: 119

Can you delete rows in BigQuery from Python script?

Hi is there a way for deleting rows in BigQuery from a Python Script? I tried looking in the documentation and finding an example on internet, but I could not find anything.

Something that looks like this.

table_id = "a.dataset.table"  # Table ID for faulty_gla_entry

statement = """ DELETE FROM a.dataset.table where value = 2 """

client.delete(table_id, statement)

Upvotes: 0

Views: 1460

Answers (2)

Raul Saucedo
Raul Saucedo

Reputation: 1780

here you can see a code a documentation to execute a query with python

You can see this example code, with the “Delete” statement.

from google.cloud import bigquery 
client = bigquery.Client() 
dml_statement = ( 
"Delete from dataset.Inventory where ID=5"
) 
query_job = client.query(dml_statement) # API request 
query_job.result() # Waits for statement to finish

How to build queries in BigQuery

Upvotes: 1

14mble
14mble

Reputation: 119

Like @SergeyGeron stated. https://googleapis.dev/python/bigquery/latest/usage/index.html#bigquery-basics has nice stuff.

Wrote something like this.

from google.cloud import bigquery

client = bigquery.Client()

query = """DELETE FROM a.dataset.table WHERE value = 4"""
query_job = client.query(query)
print(query_job.result())

Upvotes: 1

Related Questions