@@ -37,6 +37,9 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
3737 ATTACH PARTITION <replaceable class="parameter">partition_name</replaceable> { FOR VALUES <replaceable class="parameter">partition_bound_spec</replaceable> | DEFAULT }
3838ALTER TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
3939 DETACH PARTITION <replaceable class="parameter">partition_name</replaceable> [ CONCURRENTLY | FINALIZE ]
40+ ALTER TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
41+ MERGE PARTITIONS (<replaceable class="parameter">partition_name1</replaceable>, <replaceable class="parameter">partition_name2</replaceable> [, ...])
42+ INTO <replaceable class="parameter">partition_name</replaceable>
4043
4144<phrase>where <replaceable class="parameter">action</replaceable> is one of:</phrase>
4245
@@ -1118,14 +1121,74 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
11181121 </listitem>
11191122 </varlistentry>
11201123
1124+ <varlistentry id="sql-altertable-merge-partitions">
1125+ <term><literal>MERGE PARTITIONS (<replaceable class="parameter">partition_name1</replaceable>, <replaceable class="parameter">partition_name2</replaceable> [, ...]) INTO <replaceable class="parameter">partition_name</replaceable></literal></term>
1126+
1127+ <listitem>
1128+ <para>
1129+ This form merges several partitions into the one partition of the target table.
1130+ Hash-partitioning is not supported. If DEFAULT partition is not in the
1131+ list of partitions <replaceable class="parameter">partition_name1</replaceable>,
1132+ <replaceable class="parameter">partition_name2</replaceable> [, ...]:
1133+ <itemizedlist>
1134+ <listitem>
1135+ <para>
1136+ For range-partitioned tables is necessary that the ranges
1137+ of the partitions <replaceable class="parameter">partition_name1</replaceable>,
1138+ <replaceable class="parameter">partition_name2</replaceable> [, ...] can
1139+ be merged into one range without spaces and overlaps (otherwise an error
1140+ will be generated). The combined range will be the range for the partition
1141+ <replaceable class="parameter">partition_name</replaceable>.
1142+ </para>
1143+ </listitem>
1144+ <listitem>
1145+ <para>
1146+ For list-partitioned tables the values lists of all partitions
1147+ <replaceable class="parameter">partition_name1</replaceable>,
1148+ <replaceable class="parameter">partition_name2</replaceable> [, ...] are
1149+ combined and form a list of values of partition
1150+ <replaceable class="parameter">partition_name</replaceable>.
1151+ </para>
1152+ </listitem>
1153+ </itemizedlist>
1154+ If DEFAULT partition is in the list of partitions <replaceable class="parameter">partition_name1</replaceable>,
1155+ <replaceable class="parameter">partition_name2</replaceable> [, ...]:
1156+ <itemizedlist>
1157+ <listitem>
1158+ <para>
1159+ The partition <replaceable class="parameter">partition_name</replaceable>
1160+ will be the DEFAULT partition.
1161+ </para>
1162+ </listitem>
1163+ <listitem>
1164+ <para>
1165+ For range- and list-partitioned tables the ranges and lists of values
1166+ of the merged partitions can be any.
1167+ </para>
1168+ </listitem>
1169+ </itemizedlist>
1170+ The new partition <replaceable class="parameter">partition_name</replaceable>
1171+ can have the same name as one of the merged partitions. Only simple,
1172+ non-partitioned partitions can be merged.
1173+ </para>
1174+ <note>
1175+ <para>
1176+ This command acquires an <literal>ACCESS EXCLUSIVE</literal> lock.
1177+ This is a significant limitation, which limits the usage of this
1178+ command with large partitioned tables under a high load.
1179+ </para>
1180+ </note>
1181+ </listitem>
1182+ </varlistentry>
1183+
11211184 </variablelist>
11221185 </para>
11231186
11241187 <para>
11251188 All the forms of ALTER TABLE that act on a single table, except
11261189 <literal>RENAME</literal>, <literal>SET SCHEMA</literal>,
1127- <literal>ATTACH PARTITION</literal>, and
1128- <literal>DETACH PARTITION </literal> can be combined into
1190+ <literal>ATTACH PARTITION</literal>, <literal>DETACH PARTITION</literal>,
1191+ and <literal>MERGE PARTITIONS </literal> can be combined into
11291192 a list of multiple alterations to be applied together. For example, it
11301193 is possible to add several columns and/or alter the type of several
11311194 columns in a single command. This is particularly useful with large
@@ -1368,7 +1431,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
13681431 <term><replaceable class="parameter">partition_name</replaceable></term>
13691432 <listitem>
13701433 <para>
1371- The name of the table to attach as a new partition or to detach from this table.
1434+ The name of the table to attach as a new partition or to detach from this table,
1435+ or the name of the new merged partition.
13721436 </para>
13731437 </listitem>
13741438 </varlistentry>
@@ -1784,6 +1848,13 @@ ALTER TABLE measurement
17841848 DETACH PARTITION measurement_y2015m12;
17851849</programlisting></para>
17861850
1851+ <para>
1852+ To merge several partitions into one partition of the target table:
1853+ <programlisting>
1854+ ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_central)
1855+ INTO sales_all;
1856+ </programlisting></para>
1857+
17871858 </refsect1>
17881859
17891860 <refsect1>
0 commit comments