DEFAULT Partition Catches Unrouted Rows

A DEFAULT partition absorbs rows no other partition accepts, and blocks CREATE TABLE ... PARTITION OF until conflicting rows are moved out.

SqlData Integrity

Code

snippet
-- the DEFAULT partition catches rows no other partition accepts
CREATE TABLE telemetry (
    region text NOT NULL,
    metric text NOT NULL,
    value  numeric NOT NULL
) PARTITION BY LIST (region);

CREATE TABLE telemetry_apac PARTITION OF telemetry FOR VALUES IN ('apac');
CREATE TABLE telemetry_default PARTITION OF telemetry DEFAULT;

INSERT INTO telemetry VALUES
    ('apac', 'cpu', 0.42),
    ('emea', 'cpu', 0.31),   -- emea 还没有专属分区:落进 DEFAULT
    ('antarctica', 'cpu', 0.17);

SELECT tableoid::regclass AS partition_name, region, metric
FROM telemetry ORDER BY region;

-- emea 专属分区来了:DEFAULT 分区约束要改,里面有 'emea' 行 → 拒绝
CREATE TABLE telemetry_emea PARTITION OF telemetry FOR VALUES IN ('emea');
-- ERROR: updated partition constraint for default partition "telemetry_default"
--        would be violated by some row

-- 先清走命中的行,建分区才能成功
DELETE FROM telemetry WHERE region = 'emea';
CREATE TABLE telemetry_emea PARTITION OF telemetry FOR VALUES IN ('emea');

SELECT tableoid::regclass AS partition_name, region
FROM telemetry ORDER BY region;

DROP TABLE telemetry;

The catch-all partition at work

telemetry is PARTITION BY LIST (region) with one explicit partition (telemetry_apac for ‘apac’) and one DEFAULT partition. The three inserts show the routing: ‘apac’ goes to its own partition, while ‘emea’ and ‘antarctica’ — no dedicated partition exists — fall into telemetry_default instead of erroring. The first inventory query reads tableoid::regclass to name each row’s physical home.

The first inventory, and the failed promotion

 partition_name    | region
-------------------+-----------
 telemetry_default | antarctica
 telemetry_apac    | apac
 telemetry_default | emea

Creating telemetry_emea FOR VALUES IN ('emea') is rejected with the exact error the file quotes (updated partition constraint for default partition "telemetry_default" would be violated by some row): promoting ‘emea’ out of DEFAULT means re-checking every DEFAULT row against the new constraint, and one ‘emea’ row is sitting there. The script then deletes that row, and the identical CREATE TABLE … PARTITION OF succeeds — the final query lists antarctica in DEFAULT and apac in its own partition.

The line that requires the cleanup first

CREATE TABLE telemetry_emea PARTITION OF telemetry FOR VALUES IN ('emea');

Same statement, two outcomes: with a conflicting row present it errors, after DELETE FROM telemetry WHERE region = 'emea' it succeeds — the DEFAULT partition’s contents gate new partitions.

Interactive Tools for This Topic

FAQ

Which tables does this file reference?
The references are `telemetry`.