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;

-- 
Justin


Reply via email to