0

I'm using the following python code to delete some rows in a bigquery table:

from google.cloud import bigquery

bigquery_client = bigquery.Client(project='my-project')

query_delete = f"""
    delete from `my_table` where created_at >= '2021-01-01'
"""
print(query_delete)
# query_delete
job = bigquery_client.query(query)
job.result()
print("Deleted!")

However, the rows don't seem to be deleted when doing this from python. What am I missing?

David Masip
  • 2,146
  • 1
  • 26
  • 46

2 Answers2

2

I think below code snippet should work for you. You should pass query_delete instead of query

from google.cloud import bigquery

bigquery_client = bigquery.Client(project='my-project')

query_delete = f"""
  delete from `my_table` where created_at >= '2021-01-01'
"""

print(query_delete)
job = bigquery_client.query(query_delete)
job.result()
print("Deleted!")

Or you can try below formatted query

query_delete = (
  "DELETE from my_table "
  "WHERE created_at >= '2021-01-01'"
)
Sabil
  • 3,750
  • 1
  • 5
  • 16
0

You probably need to enable standard SQL in BigQuery table.

https://stackoverflow.com/a/42831957/1683626

It should be set as default as is noted in official documentation, but maybe you changed it to legacy sql.

In the Cloud Console and the client libraries, standard SQL is the default.

y0j0
  • 3,369
  • 5
  • 31
  • 52