5

I'm using the BQ CLI (https://cloud.google.com/bigquery/bq-command-line-tool).

I didn't find how to Delete DAY Partition data.

For example, i have a DAY PARTITIONED table that holds data for dates 2016-09-01 and until 2016-09-30.

I need to delete the "2016-09-15" partition completely.

Is this possible through CLI command ?

user4157124
  • 2,809
  • 13
  • 27
  • 42
shayms8
  • 671
  • 6
  • 13
  • 28

4 Answers4

5

If you do want to delete a partition you can use the bq rm command while specifying a $YYYYMMDD table decorator. For your case the command would look like:

bq rm -t 'dataset.table$20160915'

Be careful to include the single quotes, otherwise the decorator may get expanded to an empty variable and you'll delete the full table.

hamdog
  • 991
  • 2
  • 10
  • 24
4

You likely do not have to delete it to re-insert the data. See this link for details about how to re-state data in a specific portion of your date partitioned table.

Basically, just use the --replace flag with the $YYYYMMDD table decorator with the bq CLI tool.

andre622
  • 495
  • 3
  • 16
1

Simple way we can Update it Through CLI:-

bq update --time_partitioning_expiration (time in second) Dataset.table_name
David Buck
  • 3,752
  • 35
  • 31
  • 35
Kumar Pankaj Dubey
  • 1,541
  • 3
  • 17
  • 17
  • With partitioned table: ```BigQuery error in update operation: Cannot change partitioning/clustering spec for a partitioned/clustered table.``` With non partitioned table: ```Cannot convert non partitioned table to partitioned table.``` – Quockhanh Pham Nov 07 '22 at 02:47
  • Try: ```bq update --default_partition_expiration integer project_id:dataset``` – Quockhanh Pham Nov 07 '22 at 02:51
0

Step 1: Select the project in which the dataset (and thus table) exists

gcloud config set project <project-name>

Note: You can see the full list of available projects using gcloud projects list

Step 2: Delete the desired partition

bq rm -t 'dataset.table$partition'

Otherwise, you can even delete a partition from a table even when working on a separate project. But in this case you'd have to specify it in the command:

bq rm -t project_id:dataset.table$partition
Giorgos Myrianthous
  • 36,235
  • 20
  • 134
  • 156