'How can I drop a BigQuery partitioned table?

I don't want to delete tables one by one.
What is the fastest way to do it?



Solution 1:[1]

The process for deleting a time-partitioned table and all the partitions in it are the same as the process for deleting a standard table.

So if you delete a partition table without specifying the partition it will delete all tables. You don't have to delete one by one.

DROP TABLE <tablename>

Solution 2:[2]

You can also delete programmatically (i.e. java). Use the sample code of DeleteTable.java and change the flow to have a list of all your tables and partitions to be deleted. In case needed for deletion of specific partitions only, you can refer to a table partition (i.e. partition by day) in the following way:

String mainTable = "TABLE_NAME"; // i.e. my_table
String partitionId = "YYYYMMDD"; // i.e. 20200430
String decorator = "$";
String tableName = mainTable+decorator+partitionId;

Here is the guide to run java BigQuery samples, and ensure to set your project in the cloud shell:

gcloud config set project <project-id>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2