Last active
November 5, 2023 04:48
-
-
Save MatthewDaniels/b76a6acdd27f315e86f952a790f3601e to your computer and use it in GitHub Desktop.
Delete all the tables within a Dataset in BigQuery using the bq command line utility.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# VARS | |
PROJECT=my-project | |
DATASET_NAME=Datisan_TEST | |
# tables will have the structure day_tables_prefix_yyyyMMdd (sharded daily tables) | |
TABLE_PREFIX=day_tables_prefix | |
# make sure we are on the right project | |
echo | |
echo 'Make sure we are on the correct project...' | |
gcloud config set project $PROJECT | |
# test the function by sending a pub/sub topic message | |
echo | |
echo 'Deleting the tables...' | |
for table in `bq ls --max_results=10000000 $DATASET_NAME | grep TABLE | grep $TABLE_PREFIX |awk '{print $1}'`; | |
do | |
FQ_TABLE_NAME=$PROJECT:$DATASET_NAME.$table | |
echo $FQ_TABLE_NAME; | |
bq rm -f -t $FQ_TABLE_NAME; | |
done | |
echo | |
echo 'Check the output to ensure all is well in the world...' | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment