@@ -37,6 +37,9 @@ ALTER TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
37
37
ATTACH PARTITION <replaceable class="parameter">partition_name</replaceable> { FOR VALUES <replaceable class="parameter">partition_bound_spec</replaceable> | DEFAULT }
38
38
ALTER TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
39
39
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>
40
43
41
44
<phrase>where <replaceable class="parameter">action</replaceable> is one of:</phrase>
42
45
@@ -1118,14 +1121,74 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1118
1121
</listitem>
1119
1122
</varlistentry>
1120
1123
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
+
1121
1184
</variablelist>
1122
1185
</para>
1123
1186
1124
1187
<para>
1125
1188
All the forms of ALTER TABLE that act on a single table, except
1126
1189
<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
1129
1192
a list of multiple alterations to be applied together. For example, it
1130
1193
is possible to add several columns and/or alter the type of several
1131
1194
columns in a single command. This is particularly useful with large
@@ -1368,7 +1431,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1368
1431
<term><replaceable class="parameter">partition_name</replaceable></term>
1369
1432
<listitem>
1370
1433
<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.
1372
1436
</para>
1373
1437
</listitem>
1374
1438
</varlistentry>
@@ -1784,6 +1848,13 @@ ALTER TABLE measurement
1784
1848
DETACH PARTITION measurement_y2015m12;
1785
1849
</programlisting></para>
1786
1850
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
+
1787
1858
</refsect1>
1788
1859
1789
1860
<refsect1>
0 commit comments