Skip to content

p_order := DESC causes partition_data_proc to fail #828

@mattklein

Description

@mattklein

I set up a parent table with monthly partitions:

SELECT partman.create_parent(
 p_parent_table => 'my_table',
 p_control      => 'start_timestamp',
 p_type         => 'range',
 p_interval     => '1 month',
 p_premake      => 3);

That creates partitions as expected (today is 2025-11-05):

Partitions: my_table_p20250801 FOR VALUES FROM ('2025-08-01 00:00:00+00') TO ('2025-09-01 00:00:00+00'),
            my_table_p20250901 FOR VALUES FROM ('2025-09-01 00:00:00+00') TO ('2025-10-01 00:00:00+00'),
            my_table_p20251001 FOR VALUES FROM ('2025-10-01 00:00:00+00') TO ('2025-11-01 00:00:00+00'),
            my_table_p20251101 FOR VALUES FROM ('2025-11-01 00:00:00+00') TO ('2025-12-01 00:00:00+00'),
            my_table_p20251201 FOR VALUES FROM ('2025-12-01 00:00:00+00') TO ('2026-01-01 00:00:00+00'),
            my_table_p20260101 FOR VALUES FROM ('2026-01-01 00:00:00+00') TO ('2026-02-01 00:00:00+00'),
            my_table_p20260201 FOR VALUES FROM ('2026-02-01 00:00:00+00') TO ('2026-03-01 00:00:00+00'),
            my_table_default DEFAULT

Then I can successfully call partition_data_proc with a p_interval less than the partition size:

CALL partman.partition_data_proc(
 p_parent_table := 'my_table',
 p_source_table := 'my_table_nonpartitioned',
 p_interval     := '1 hour');

But if I instead try the same call using p_order := DESC, this call fails:

CALL partman.partition_data_proc(
 p_parent_table := 'my_table',
 p_source_table := 'my_table_nonpartitioned',
 p_interval     := '1 hour',
 p_order        := 'DESC');

With this error:

ERROR:  relation "my_table_p20251105" does not exist

Note that it's attempting to insert data into a partition (20251105) that doesn't exist. It seems to be basing that on the current date / the "beginning" of the DESCENDING ordering -- instead of basing it on the MONTH START of that date.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions