Sub topic 6
Defining Bounds Without Gaps or Overlaps
Assume you know basic PostgreSQL table definitions, constraints, indexes, and simple query plans. This chapter focuses on how partition bounds describe which rows belong in each partition.
A partition bound is the rule that maps a row to a partition. PostgreSQL checks these rules when you create or attach partitions. Bounds for partitions of the same parent cannot overlap, but they can leave gaps.
Range bounds use half-open intervals
Range partitions normally use an inclusive lower bound and an exclusive upper bound:
CREATE TABLE orders (
order_id bigint NOT NULL,
order_date date NOT NULL
) PARTITION BY RANGE (order_date);
CREATE TABLE orders_2026_01
PARTITION OF orders
FOR VALUES FROM ('2026-01-01') TO ('2026-02-01');
CREATE TABLE orders_2026_02
PARTITION OF orders
FOR VALUES FROM ('2026-02-01') TO ('2026-03-01');The first partition accepts dates from 2026-01-01 through 2026-01-31. It does not accept 2026-02-01. That date belongs to orders_2026_02.
This convention makes adjacent partitions meet exactly without sharing a boundary:
| Partition | Lower bound | Upper bound | Includes |
|---|---|---|---|
| `orders_2026_01` | `2026-01-01` | `2026-02-01` | Lower bound, not upper bound |
A gap exists if you create January and March partitions but no February partition. An insert for a February date then fails unless a default partition can accept it.
Check the boundary cases
Test values exactly at both ends of every range. These cases expose most mistakes:
INSERT INTO orders (order_id, order_date)
VALUES
(1, DATE '2026-01-01'),
(2, DATE '2026-01-31'),
(3, DATE '2026-02-01');The first two rows route to orders_2026_01. The third routes to orders_2026_02. A value such as 2025-12-31 has no matching partition in this example.
You can inspect the physical partition selected for a row with tableoid:
SELECT tableoid::regclass AS physical_partition, order_id, order_date
FROM orders
ORDER BY order_id;Bounds for list and hash partitions
List partitions use sets of values. A value must appear in at most one partition.
CREATE TABLE tickets (
ticket_id bigint NOT NULL,
status text NOT NULL
) PARTITION BY LIST (status);
CREATE TABLE tickets_active
PARTITION OF tickets
FOR VALUES IN ('open', 'pending');
CREATE TABLE tickets_closed
PARTITION OF tickets
FOR VALUES IN ('closed');Hash partitions use a modulus and remainder. For complete coverage, create every remainder from zero through modulus minus one.
Exercise
Which partition receives DATE '2026-02-01' when January is FROM ('2026-01-01') TO ('2026-02-01') and February starts at FROM ('2026-02-01')?
Show answer
The February partition, because range lower bounds are inclusive and upper bounds are exclusive.