Re: Add SPLIT PARTITION/MERGE PARTITIONS commands

Pavel Borisov <pashkin.elfe@gmail.com>

From: Pavel Borisov <pashkin.elfe@gmail.com>
To: Justin Pryzby <pryzby@telsasoft.com>
Cc: Alexander Korotkov <aekorotkov@gmail.com>, Dmitry Koval <d.koval@postgrespro.ru>, Alexander Lakhin <exclusion@gmail.com>, pgsql-hackers@lists.postgresql.org, Tomas Vondra <tomas.vondra@enterprisedb.com>, Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: 2026-06-26T13:47:06Z
Lists: pgsql-hackers
Hi, Justin!

On Fri, 26 Jun 2026 at 17:40, Justin Pryzby <pryzby@telsasoft.com> wrote:
>
> Thanks for addressing the tablespace issue.
>
> One more thing -- merging non-contiguous tables is currently refused:
>
> ts=# CREATE TABLE a(t timestamptz) PARTITION BY RANGE (t);
> ts=# CREATE TABLE a_20260101 PARTITION OF a FOR VALUES FROM ('20260101')TO('20260102');
> ts=# CREATE TABLE a_20260126 PARTITION OF a FOR VALUES FROM ('20260126')TO('20260127');
> ts=# CREATE TABLE a_20260127 PARTITION OF a FOR VALUES FROM ('20260127')TO('20260128');
> ts=# CREATE TABLE a_20260128 PARTITION OF a FOR VALUES FROM ('20260128')TO('20260129');
>
> ts=# ALTER TABLE a MERGE PARTITIONS (a_20260101,a_20260126,a_20260127,a_20260128) INTO a_202601;
> ERROR:  cannot merge partition "a_20260126" together with partition "a_20260101"
> DETAIL:  The lower bound of partition "a_20260126" is not equal to the upper bound of partition "a_20260101".
> HINT:  ALTER TABLE ... MERGE PARTITIONS requires the partition bounds to be adjacent.
>
> The goal seems to be to avoid overlapping partition constaints.
>
> If there's a default partition, that also avoids the possibility of
> needing to move *some* (but not all) tuples from it into the merged
> partition.
>
> I think there should be separate logic depending on the existance of a
> default partition:
>
> - The existing logic seems to correctly handle the case of a default
>   partition, which is being merged (gap is allowed).
>
> - The case of a default partition which is not being merged is also
>   handled: no gap is allowed.  Actually, this case was probably the
>   motivation behind checking that the partitions are adjacent.
>
> - If there's *no* default partition, then I think the check should be
>   relaxed; it's sufficient to verify that the bounds of the merged
>   partition do not overlap with any partition which is not being merged;

Thank you for reporting on this feature!
Yes, I think main motivation for not allowing a partition bounds gaps for
merge was the complication in case a DEFAULT partition exists.
Probably, this could be relaxed when there is no DEFAULT partition.

Regards,
Pavel Borisov
Supabase



Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. doc: clarify MERGE PARTITIONS adjacency requirement

  2. Take into account default_tablespace during MERGE/SPLIT PARTITION(S)

  3. Create TOAST table for partitions made by MERGE/SPLIT PARTITION

  4. Adjust errcode in checkPartition()

  5. Fix usage of palloc() in MERGE/SPLIT PARTITION(s) code

  6. Implement ALTER TABLE ... SPLIT PARTITION ... command

  7. Implement ALTER TABLE ... MERGE PARTITIONS ... command

  8. Calculate agglevelsup correctly when Aggref contains a CTE.

  9. Use PqMsg_* macros in applyparallelworker.c.

  10. Restrict psql meta-commands in plain-text dumps.

  11. Ensure we have a snapshot when updating various system catalogs.

  12. Use specific collation where needed in new test

  13. Expand virtual generated columns in the planner

  14. Virtual generated columns

  15. Define PG_LOGICAL_DIR for path pg_logical/ in data folder

  16. Revert support for ALTER TABLE ... MERGE/SPLIT PARTITION(S) commands

  17. Avoid repeated table name lookups in createPartitionTable()

  18. Provide deterministic order for catalog queries in partition_split.sql

  19. Don't copy extended statistics during MERGE/SPLIT partition operations

  20. Fix the name collision detection in MERGE/SPLIT partition operations

  21. Fix regression tests conflict in 3ca43dbbb6

  22. Add permission check for MERGE/SPLIT partition operations

  23. Fix one more portability shortcoming in new test_pg_dump test.

  24. Inherit parent's AM for partition MERGE/SPLIT operations

  25. Add tab completion for partition MERGE/SPLIT operations

  26. Rename tables in tests of partition MERGE/SPLIT operations

  27. Make new partitions with parent's persistence during MERGE/SPLIT

  28. Document the way partition MERGE/SPLIT operations create new partitions

  29. Change the way ATExecMergePartitions() handles the name collision

  30. Grammar fixes for split/merge partitions code

  31. Checks for ALTER TABLE ... SPLIT/MERGE PARTITIONS ... commands

  32. Fix some grammer errors from error messages and codes comments

  33. Support TZ and OF format codes in to_timestamp().

  34. Support identity columns in partitioned tables

  35. Fix indentation in twophase.c

  36. Fix corner-case planner failure for MERGE.

  37. Doc: fix documentation example for bytea hex output format.

  38. Avoid repeated name lookups during table and index DDL.