Google BigQuery - how to delete a table using bq command?

The Google BigQuery - bq team allows you to create, load, query, and modify a table.

I have not found any documentation regarding dropping a table, I will be glad to know how to do it.

I found the bq tool much easier to implement instead of writing a python interface for each command.

Thanks.

+5
source share
3 answers

found this:

bq rm -f -t data_set.table_name

-t for table -f for strength

great tool.

+16
source

Is there a way to mass delete multiple tables? - activelearner

In bash, you can do something like:

for i in $(bq ls -n 9999 my_dataset | grep keyword | awk '{print $1}'); do bq rm -ft my_dataset.$i; done; 

Explanation:

  • bq ls -n 9999 my_dataset - list of up to 9999 tables in my dataset
  • | grep keyword | grep keyword - transfer the results of the previous command to grep, find a keyword that has common tables.
  • | awk '{print $1}' | awk '{print $1}' - pass the results of the previous command to awk and print only the first column
  • Wrap it all in a for loop
  • do bq rm -ft my_dataset.$i; done; - delete each table from your data set

I highly recommend running the commands to list the tables you want to delete before adding "do bq rm". This way you can make sure that you only delete the tables that you want to delete.

+4
source

I used the for loop command line to delete the month of the table data, but it depends on the name of your table:

for %d in (01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) DO bq rm -f -t dataset.tablename_201701%d

0
source

All Articles