CodeBlanks Logo Icon CodeBlanks

Range partition

Partition by a value range.

Range partition

Range partition splits by value range. Ideal for date ranges.

CREATE TABLE sales (...) PARTITION BY RANGE (sale_date);
CREATE TABLE sales_2026_q1 PARTITION OF sales
  FOR VALUES FROM ('2026-01-01') TO ('2026-04-01');

Partition for Q1 2026.

The table sales is created.

Range partition — details

Range partition defines ranges with FROM and TO. Each range is a separate partition.

For example, FOR VALUES FROM ('2026-01-01') TO ('2027-01-01') covers the year 2026; the end value is excluded, so ranges don't overlap.

Practice Range partition

Create the sales_2026_q1 partition with FOR VALUES FROM ('2026-01-01') TO ('2026-04-01').

Starter code

query.sql
-- range partition
CREATE TABLE sales_2026_q1 PARTITION OF sales

Sample solution

query.sql
CREATE TABLE sales_2026_q1 PARTITION OF sales
  FOR VALUES FROM ('2026-01-01') TO ('2026-04-01');

Expected output

Bölüm oluşturuldu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Add RANGE

Question
PARTITION BY ____ (sale_date)
Answer
PARTITION BY RANGE (sale_date)

Explanation: RANGE partitioning splits the table by ranges of values such as dates.

2 What does range partition split by?

  • A list
  • Color
  • A hash
  • A range of values Correct answer

Explanation: Range partition splits by value range.

3 Range partition: match the terms

Term Meaning
RANGE range
FROM start
TO end
date partition

All lessons in Advanced