I have a partitioned table created in BigQuery like this:
CREATE TABLE IF NOT EXISTS `{{ my_project }}.{{ my_dataset }}.my_table`
(
dt TIMESTAMP
, other_fields
)
PARTITION BY DATE(dt)
OPTIONS(
partition_expiration_days=180
)
- Partitioned by: DAY
- Partitioning Field: dt (type: TIMESTAMP)
As you may see, the partitioning field is TIMESTAMP
but I want to parition by DAY
not by TIMESTAMP
. So what is the correct way to prune partitions? Can I cast the partitioning field to DATE
like approach 1 or I have to go with approach 2?
- Approach 1:
SELECT COUNT(*) FROM `my_project.my_dataset.my_table` WHERE CAST(dt AS DATE) = "2019-01-01"
- Approach 2:
SELECT COUNT(*) FROM `my_project.my_dataset.my_table` WHERE dt >= "2019-01-01 00:00:00" AND dt < "2019-01-02 00:00:00"