You can simply use Data Manipulation Language (DML) statements instead of SQL queries when using the Google BigQuery API.
For instance, in order to update specific rows in the following table:
Inventory+-------------------+----------+--------------------+| product | quantity | supply_constrained |+-------------------+----------+--------------------+| dishwasher | 30 | NULL || dryer | 30 | NULL || front load washer | 30 | NULL || microwave | 30 | NULL |+-------------------+----------+--------------------+
you could use the following code:
from google.cloud import bigqueryclient = bigquery.Client()dml_statement = ("UPDATE dataset.Inventory ""SET quantity = quantity - 10 ""WHERE product like '%washer%'")query_job = client.query(dml_statement) # API requestquery_job.result() # Waits for statement to finish
obtaining the following results:
Inventory+-------------------+----------+--------------------+| product | quantity | supply_constrained |+-------------------+----------+--------------------+| dishwasher | 20 | NULL || dryer | 30 | NULL || front load washer | 20 | NULL || microwave | 30 | NULL |+-------------------+----------+--------------------+