@@ -37,6 +37,8 @@ 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> [, ...]) INTO <replaceable class="parameter">partition_name</replaceable>
40
42
41
43
<phrase>where <replaceable class="parameter">action</replaceable> is one of:</phrase>
42
44
@@ -1147,14 +1149,101 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1147
1149
</listitem>
1148
1150
</varlistentry>
1149
1151
1152
+ <varlistentry id="sql-altertable-merge-partitions">
1153
+ <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>
1154
+
1155
+ <listitem>
1156
+ <para>
1157
+ This form merges several partitions of the target table into a new partition.
1158
+ Hash-partitioned target table is not supported.
1159
+ If <literal>DEFAULT</literal> partition is not in the
1160
+ list of partitions <replaceable class="parameter">partition_name1</replaceable>,
1161
+ <replaceable class="parameter">partition_name2</replaceable> [, ...]:
1162
+ <itemizedlist>
1163
+ <listitem>
1164
+ <para>
1165
+ For range-partitioned tables, the ranges of the partitions
1166
+ <replaceable class="parameter">partition_name1</replaceable>,
1167
+ <replaceable class="parameter">partition_name2</replaceable>, [...]
1168
+ must be adjacent in order to be merged. Otherwise, an error will be
1169
+ raised. The resulting combined range will be the new partition bound
1170
+ for the partition <replaceable class="parameter">partition_name</replaceable>.
1171
+ </para>
1172
+ </listitem>
1173
+ <listitem>
1174
+ <para>
1175
+ For list-partitioned tables, the partition bounds of
1176
+ <replaceable class="parameter">partition_name1</replaceable>,
1177
+ <replaceable class="parameter">partition_name2</replaceable>, [...]
1178
+ are combined to form the new partition bound for
1179
+ <replaceable class="parameter">partition_name</replaceable>.
1180
+ </para>
1181
+ </listitem>
1182
+ </itemizedlist>
1183
+ If <literal>DEFAULT</literal> partition is in the list of partitions <replaceable class="parameter">partition_name1</replaceable>,
1184
+ <replaceable class="parameter">partition_name2</replaceable> [, ...]:
1185
+ <itemizedlist>
1186
+ <listitem>
1187
+ <para>
1188
+ The partition <replaceable class="parameter">partition_name</replaceable>
1189
+ will be the new <literal>DEFAULT</literal> partition of the target table.
1190
+ </para>
1191
+ </listitem>
1192
+ <listitem>
1193
+ <para>
1194
+ The partition bound specifications for all partitions-
1195
+ <replaceable class="parameter">partition_name1</replaceable>,
1196
+ <replaceable class="parameter">partition_name2</replaceable>, [...]
1197
+ can be arbitrary.
1198
+ </para>
1199
+ </listitem>
1200
+ </itemizedlist>
1201
+ The new partition <replaceable class="parameter">partition_name</replaceable>
1202
+ can have the same name as one of the merged partitions. Only simple,
1203
+ non-partitioned partitions can be merged.
1204
+ </para>
1205
+ <para>
1206
+ If merged partitions have different owners, an error will be generated.
1207
+ The owner of the merged partitions will be the owner of the new partition.
1208
+ It is the user's responsibility to setup <acronym>ACL</acronym> on the
1209
+ new partition.
1210
+ </para>
1211
+ <para>
1212
+ The indexes and identity are created later, after moving the data
1213
+ into the new partition.
1214
+ Extended statistics aren't copied from the parent table, for consistency with
1215
+ <command>CREATE TABLE PARTITION OF</command>.
1216
+ The new partition will inherit the same table access method, persistence
1217
+ type, and tablespace as the parent table.
1218
+ </para>
1219
+ <para>
1220
+ When partitions are merged, any individual objects belonging to those
1221
+ partitions, such as constraints or statistics will be dropped. This occurs
1222
+ because <command>ALTER TABLE MERGE PARTITIONS</command> uses the partitioned table itself as the
1223
+ template to define these objects.
1224
+ </para>
1225
+ <para>
1226
+ If merged partitions have some objects dependent on them, the command can
1227
+ not be done (<literal>CASCADE</literal> is not used, an error will be returned).
1228
+ </para>
1229
+ <note>
1230
+ <para>
1231
+ Merging partitions acquires a <literal>ACCESS EXCLUSIVE</literal> lock on
1232
+ the parent table, in addition to the <literal>ACCESS EXCLUSIVE</literal>
1233
+ locks on the tables being merged and on the default partition (if any).
1234
+ </para>
1235
+ </note>
1236
+ </listitem>
1237
+ </varlistentry>
1238
+
1150
1239
</variablelist>
1151
1240
</para>
1152
1241
1153
1242
<para>
1154
1243
All the forms of <command>ALTER TABLE</command> that act on a single table,
1155
1244
except <literal>RENAME</literal>, <literal>SET SCHEMA</literal>,
1156
- <literal>ATTACH PARTITION</literal>, and
1157
- <literal>DETACH PARTITION </literal> can be combined into
1245
+ <literal>ATTACH PARTITION</literal>, <literal>DETACH PARTITION</literal>,
1246
+ and <literal>MERGE PARTITIONS </literal> can be combined into
1158
1247
a list of multiple alterations to be applied together. For example, it
1159
1248
is possible to add several columns and/or alter the type of several
1160
1249
columns in a single command. This is particularly useful with large
@@ -1397,7 +1486,18 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1397
1486
<term><replaceable class="parameter">partition_name</replaceable></term>
1398
1487
<listitem>
1399
1488
<para>
1400
- The name of the table to attach as a new partition or to detach from this table.
1489
+ The name of the table to attach as a new partition or to detach from this table,
1490
+ or the name of the new merged partition.
1491
+ </para>
1492
+ </listitem>
1493
+ </varlistentry>
1494
+
1495
+ <varlistentry id="sql-altertable-parms-partition-name1">
1496
+ <term><replaceable class="parameter">partition_name1</replaceable></term>
1497
+ <term><replaceable class="parameter">partition_name2</replaceable></term>
1498
+ <listitem>
1499
+ <para>
1500
+ The names of the tables being merged into the new partition.
1401
1501
</para>
1402
1502
</listitem>
1403
1503
</varlistentry>
@@ -1830,6 +1930,13 @@ ALTER TABLE measurement
1830
1930
DETACH PARTITION measurement_y2015m12;
1831
1931
</programlisting></para>
1832
1932
1933
+ <para>
1934
+ To merge several partitions into one partition of the target table:
1935
+ <programlisting>
1936
+ ALTER TABLE sales_list MERGE PARTITIONS (sales_west, sales_east, sales_central)
1937
+ INTO sales_all;
1938
+ </programlisting></para>
1939
+
1833
1940
</refsect1>
1834
1941
1835
1942
<refsect1>
0 commit comments