Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete BigQuery tables with wildcard

Is there any way to delete tables from the command line with a wildcard? Say I have a set of dated tables that I want to delete, with the same prefix - can I delete them all in one go, without writing my own shell script?

like image 703
JasonB Avatar asked Apr 05 '16 17:04

JasonB


3 Answers

Not the nicest but you can generate a query to delete the tables via:

select concat("drop table ",table_schema,".",   table_name, ";" )
from <insert_your_dataset_name>.INFORMATION_SCHEMA.TABLES
where table_name like "INSERT_YOUR_TABLE_NAME_%"
order by table_name desc

After running that click "Save Results", select "Copy to clipboard" from the dropdown.

like image 83
Henry Munro Avatar answered Oct 30 '22 22:10

Henry Munro


Nope, gotta script it. You can delete an entire dataset at once, but there's no way to use a wildcard to delete a subset of the tables in a dataset.

like image 45
Jeremy Condit Avatar answered Oct 30 '22 20:10

Jeremy Condit


Following @henry answer, I couldn't do it in sql (don't know why) so I adapted the concat to create a bunch of lines to feed all together to the shell

select concat("bq rm -f -t ",table_schema,".",   table_name, ";" )
from <insert_your_dataset_name>.INFORMATION_SCHEMA.TABLES
where table_name like "INSERT_YOUR_TABLE_NAME_%"
order by table_name desc

Then just 'Save results' => ' Copy to clipboard' => open BQ Shell => paste!

like image 20
Marco Rossi Avatar answered Oct 30 '22 21:10

Marco Rossi