Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to drop multiple tables in Big query using Wildcards TABLE_DATE_RANGE()?

I was looking at the documentation but I haven't found the way to Drop multiple tables using wild cards.

I was trying to do something like this but it doesn't work:

DROP TABLE
 TABLE_DATE_RANGE([clients.sessions_], 
                  TIMESTAMP('2017-01-01'), 
                  TIMESTAMP('2017-05-31'))
like image 888
jfk83 Avatar asked Dec 08 '22 16:12

jfk83


2 Answers

For dataset stats and tables like daily_table_20181017 keeping dates conventions, I would go with simple script and gcloud Command-Line Tool:

for table in `bq ls --max_results=10000000 stats |grep TABLE |grep daily_table |awk '{print $1}'`; do echo stats.$table; bq rm -f -t stats.$table; done
like image 53
nimate Avatar answered Dec 10 '22 06:12

nimate


DROP TABLE [table_name]; is now supported in bigquery. So here is a purely SQL/bigquery UI solution.

select concat("drop table ",table_schema,".",   table_name, ";" )
from <dataset-name>.INFORMATION_SCHEMA.TABLES
where table_name like "partial_table_name%"
order by table_name desc

Audit that you are dropping the correct tables. Copy and paste back into bigquery to drop listed tables.

like image 36
Dengar Avatar answered Dec 10 '22 06:12

Dengar