Request a demo

BigQuery · DDL statement

BigQuery PARTITION BY (partitioned tables)

PARTITION BY in CREATE TABLE splits a BigQuery table into partitions by a DATE, TIMESTAMP or DATETIME column, by ingestion time, or by integer ranges. Queries that filter on the partitioning column read and bill only the matching partitions, which makes it the main lever on query cost.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

A partitioned table stores each day (or hour, month, year, or integer range) of data as a separate partition. When a query filters on the partitioning column with a constant, BigQuery skips the other partitions before reading anything. This is called partition pruning, and on-demand you are billed only for the partitions that remain. Because pruning is decided from metadata, a dry run shows the real cost of a partitioned query before it runs, which clustering cannot do.

There are three kinds. Time-unit column partitioning uses a DATE column directly, DATE(ts) for daily partitions of a TIMESTAMP or DATETIME, TIMESTAMP_TRUNC or DATETIME_TRUNC with HOUR, DAY, MONTH or YEAR, or DATE_TRUNC(date_col, MONTH) and YEAR. Ingestion-time partitioning (_PARTITIONDATE or TIMESTAMP_TRUNC(_PARTITIONTIME, ...)) assigns rows by load time and exposes the _PARTITIONTIME pseudocolumn; it cannot be used with CREATE TABLE ... AS SELECT. Integer-range partitioning uses RANGE_BUCKET(int_col, GENERATE_ARRAY(start, end, interval)), where end is exclusive. Time partitions follow UTC boundaries. Rows with a NULL partitioning value go to the __NULL__ partition; dates before 1960-01-01 or after 2159-12-31, and integers outside the range, go to __UNPARTITIONED__.

The limits are worth knowing before you choose a granularity. A table can have at most 10,000 partitions (older articles quote 4,000, which is now the limit on partitions a single job can modify), and an integer-range spec at most 10,000 ranges. You partition by exactly one top-level, non-repeated column. Partitioning is fixed at creation: you cannot add it to an existing table, and CREATE OR REPLACE TABLE cannot replace a table that has a different kind of partitioning, so you drop the table or build a new one with CREATE TABLE AS SELECT.

Pruning needs a filter BigQuery can evaluate without reading data: compare the bare column with constants (event_ts >= '2026-11-01'), or wrap it only in supported functions such as DATE(), DATE_TRUNC, TIMESTAMP_TRUNC, TIMESTAMP_ADD or EXTRACT(YEAR ...). Filters that take their value from a subquery, apply arithmetic or unsupported functions to the column, or are joined with OR to a condition on another column scan every partition. Set require_partition_filter = TRUE to reject queries without a usable filter, and partition_expiration_days to drop old partitions automatically.

Syntax

CREATE [OR REPLACE] TABLE table_name
  (column_definitions)
PARTITION BY partition_expression
[CLUSTER BY column[, ...]]
[OPTIONS (partition_expiration_days = n, require_partition_filter = { TRUE | FALSE })]
[AS query_statement]

partition_expression:
    date_column
  | DATE(timestamp_or_datetime_column)
  | DATE_TRUNC(date_column, { MONTH | YEAR })
  | TIMESTAMP_TRUNC(timestamp_column, { HOUR | DAY | MONTH | YEAR })
  | DATETIME_TRUNC(datetime_column, { HOUR | DAY | MONTH | YEAR })
  | _PARTITIONDATE
  | DATE(_PARTITIONTIME)
  | TIMESTAMP_TRUNC(_PARTITIONTIME, { HOUR | DAY | MONTH | YEAR })
  | RANGE_BUCKET(int64_column, GENERATE_ARRAY(start, end[, interval]))

ALTER TABLE table_name
SET OPTIONS (partition_expiration_days = n, require_partition_filter = TRUE)

Arguments and return value

ArgumentDescription
date_column / DATE(ts)Daily partitions on a DATE column, or on the UTC date of a TIMESTAMP (the calendar date of a DATETIME).
TIMESTAMP_TRUNC / DATETIME_TRUNC / DATE_TRUNCChoose the granularity: HOUR, DAY, MONTH or YEAR for TIMESTAMP and DATETIME, MONTH or YEAR for DATE.
_PARTITIONDATE / _PARTITIONTIMEIngestion-time partitioning. Rows land in the partition of the time BigQuery ingested them, or the one you name with a partition decorator. Not allowed with AS query_statement.
RANGE_BUCKET(col, GENERATE_ARRAY(start, end, interval))Integer-range partitioning on an INT64 column. start is inclusive, end exclusive, interval defaults to 1. At most 10,000 ranges.
partition_expiration_daysFLOAT64 option. Partitions older than this many days are deleted automatically, at no cost. Only valid on partitioned tables.
require_partition_filterBOOL option, default FALSE. When TRUE, queries without a filter on the partitioning column fail instead of scanning the whole table. Also enforced through views.

Returns: A table whose data is stored per partition. Queries that filter on the partitioning column read, and on-demand bill, only the matching partitions.

Examples

Daily partitions on a TIMESTAMP column, with expiration and a required filter

Each UTC day of event_ts becomes a partition, partitions older than two years are dropped automatically, and a query that forgets the date filter fails instead of scanning two years of events.

CREATE TABLE `project.dataset.events`
(
  event_id STRING,
  user_id STRING,
  event_name STRING,
  event_ts TIMESTAMP
)
PARTITION BY DATE(event_ts)
CLUSTER BY event_name, user_id
OPTIONS (
  partition_expiration_days = 730,
  require_partition_filter = TRUE
);

Filters that prune partitions, and filters that scan everything

All four queries run against the table above. Only the first two are billed for a single week or day; the last two read every partition. When the boundary comes from another table, look it up first with DECLARE and SET and filter on the variable.

-- Prunes: the bare column compared with constants
SELECT COUNT(*) FROM `project.dataset.events`
WHERE event_ts >= '2026-11-16' AND event_ts < '2026-11-23';

-- Prunes: DATE() is a supported function on the partitioning column
SELECT COUNT(*) FROM `project.dataset.events`
WHERE DATE(event_ts) = '2026-11-22';

-- Full scan: the boundary comes from a subquery
SELECT COUNT(*) FROM `project.dataset.events`
WHERE event_ts > (SELECT MAX(loaded_at) FROM `project.dataset.load_log`);

-- Full scan: OR with a condition on another column
SELECT COUNT(*) FROM `project.dataset.events`
WHERE DATE(event_ts) = '2026-11-22' OR user_id = 'u_1042';

Rebuild an unpartitioned table as a partitioned one

Partitioning cannot be added in place. Create a new monthly partitioned, clustered copy with CREATE TABLE AS SELECT (on-demand, this bills one full scan of orders), then swap the names.

CREATE TABLE `project.dataset.orders_partitioned`
PARTITION BY DATE_TRUNC(order_date, MONTH)
CLUSTER BY customer_id
OPTIONS (require_partition_filter = TRUE)
AS
SELECT * FROM `project.dataset.orders`;

DROP TABLE `project.dataset.orders`;
ALTER TABLE `project.dataset.orders_partitioned` RENAME TO orders;

Ingestion-time and integer-range partitioning

The first table partitions by the day rows arrive; filter it on _PARTITIONDATE or _PARTITIONTIME. The second creates 100 partitions of 10,000 customer IDs each; IDs of 1,000,000 and above land in __UNPARTITIONED__.

CREATE TABLE `project.dataset.raw_webhooks`
(
  source STRING,
  payload JSON
)
PARTITION BY _PARTITIONDATE
OPTIONS (partition_expiration_days = 30);

CREATE TABLE `project.dataset.customers`
(
  customer_id INT64,
  country STRING,
  signup_date DATE
)
PARTITION BY RANGE_BUCKET(customer_id, GENERATE_ARRAY(0, 1000000, 10000));

Common mistakes

  • Hiding the partitioning column inside an expression. WHERE EXTRACT(MONTH FROM event_ts) = 11, WHERE FORMAT_DATE('%Y-%m', DATE(event_ts)) = '2026-11' and WHERE event_ts + INTERVAL 1 DAY > CURRENT_TIMESTAMP() all scan every partition. Rewrite them as ranges on the bare column: event_ts >= '2026-11-01' AND event_ts < '2026-12-01', or event_ts > CURRENT_TIMESTAMP() - INTERVAL 1 DAY.
  • Filtering through a subquery or a join. WHERE event_ts > (SELECT MAX(loaded_at) FROM load_log) and filters that only come from a joined dimension table do not prune. Compute the boundary first into a script variable, or pass it as a query parameter.
  • Choosing too fine a granularity. Hourly partitions reach the 10,000 limit in about 14 months, and partitions smaller than about 10 GB each mostly add metadata; Google suggests clustering in that case. For small daily volumes over many years, partition by month and cluster by the date column.
  • Expecting partitions in local time. Time-unit partitions follow UTC, so DATE(event_ts) is the UTC date. For a business day in New York, filter with explicit bounds: event_ts >= TIMESTAMP('2026-11-22', 'America/New_York') AND event_ts < TIMESTAMP('2026-11-23', 'America/New_York').
  • Trying to partition an existing table with CREATE OR REPLACE TABLE ... PARTITION BY ... AS SELECT * FROM same_table. Replacing a table with a different kind of partitioning is not allowed; write to a new table and swap names, as in the third example.

Cost and performance

  • Pruned partitions are not read and not billed on demand: with data spread evenly, a one-day filter on a table with two years of daily partitions reads about 1/730 of it. A dry run reports the pruned estimate before you run anything.
  • A DELETE whose filter covers whole partitions and references only the partitioning column can drop those partitions without scanning bytes or using slots (a dry run that reports 0 bytes confirms it), and partition_expiration_days deletes old partitions for free. A DELETE filtered on other columns instead rewrites every partition it touches.
  • A single query or load job can modify at most 4,000 partitions, so a backfill of more than about 11 years of daily partitions must be split into several jobs. Each partition also ages into long-term storage (half price) on its own after 90 days without changes, even while newer partitions are still being written.

FAQ

How do I partition an existing BigQuery table?

You can't change partitioning in place. Create a new table with CREATE TABLE new_table PARTITION BY ... AS SELECT * FROM old_table, check it, then drop the old table and rename the new one with ALTER TABLE ... RENAME TO. On-demand, the copy bills one full scan of the old table.

What is the maximum number of partitions in a BigQuery table?

10,000 partitions per table, and 10,000 ranges for an integer-range spec. Separately, one job can modify at most 4,000 partitions. Check how many partitions a table has with total_partitions in INFORMATION_SCHEMA.TABLE_STORAGE.

What is the difference between partitioning and clustering?

Partitioning splits a table by one date, timestamp or integer column, gives an exact cost estimate before the query runs, and allows partition expiration and cheap partition deletes. Clustering sorts data by up to four columns of any cardinality, but the saving is only known after the query runs. Large tables usually use both.

Why does my query scan the whole partitioned table?

The filter can't be used for pruning: it is missing, takes its value from a subquery, applies arithmetic or an unsupported function to the partitioning column, or is combined with OR. Compare the bare column with constants and run a dry run to confirm the bytes.

Errors you may hit

More DDL statements

All BigQuery DDL statements · All statements and clauses · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.