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?
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With