@@ -37,6 +37,10 @@ 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
+ SPLIT PARTITION <replaceable class="parameter">partition_name</replaceable> INTO
42
+ (PARTITION <replaceable class="parameter">partition_name1</replaceable> { FOR VALUES <replaceable class="parameter">partition_bound_spec</replaceable> | DEFAULT },
43
+ PARTITION <replaceable class="parameter">partition_name2</replaceable> { FOR VALUES <replaceable class="parameter">partition_bound_spec</replaceable> | DEFAULT } [, ...])
40
44
ALTER TABLE [ IF EXISTS ] <replaceable class="parameter">name</replaceable>
41
45
MERGE PARTITIONS (<replaceable class="parameter">partition_name1</replaceable>, <replaceable class="parameter">partition_name2</replaceable> [, ...])
42
46
INTO <replaceable class="parameter">partition_name</replaceable>
@@ -1121,6 +1125,44 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1121
1125
</listitem>
1122
1126
</varlistentry>
1123
1127
1128
+ <varlistentry id="sql-altertable-split-partition">
1129
+ <term><literal>SPLIT PARTITION <replaceable class="parameter">partition_name</replaceable> INTO (PARTITION <replaceable class="parameter">partition_name1</replaceable> { FOR VALUES <replaceable class="parameter">partition_bound_spec</replaceable> | DEFAULT }, PARTITION <replaceable class="parameter">partition_name2</replaceable> { FOR VALUES <replaceable class="parameter">partition_bound_spec</replaceable> | DEFAULT } [, ...])</literal></term>
1130
+
1131
+ <listitem>
1132
+ <para>
1133
+ This form splits a single partition of the target table. Hash-partitioning
1134
+ is not supported. Bounds of new partitions should not overlap with new and
1135
+ existing partitions (except <replaceable class="parameter">partition_name</replaceable>).
1136
+ If the split partition is a DEFAULT partition, one of the new partitions must be DEFAULT.
1137
+ In case one of the new partitions or one of existing partitions is DEFAULT,
1138
+ new partitions <replaceable class="parameter">partition_name1</replaceable>,
1139
+ <replaceable class="parameter">partition_name2</replaceable>, ... can have spaces
1140
+ between partitions bounds. If the partitioned table does not have a DEFAULT
1141
+ partition, the DEFAULT partition can be defined as one of the new partitions.
1142
+ </para>
1143
+ <para>
1144
+ In case new partitions do not contain a DEFAULT partition and the partitioned table
1145
+ does not have a DEFAULT partition, the following must be true: sum bounds of
1146
+ new partitions <replaceable class="parameter">partition_name1</replaceable>,
1147
+ <replaceable class="parameter">partition_name2</replaceable>, ... should be
1148
+ equal to bound of split partition <replaceable class="parameter">partition_name</replaceable>.
1149
+ One of the new partitions <replaceable class="parameter">partition_name1</replaceable>,
1150
+ <replaceable class="parameter">partition_name2</replaceable>, ... can have
1151
+ the same name as split partition <replaceable class="parameter">partition_name</replaceable>
1152
+ (this is suitable in case of splitting a DEFAULT partition: we split it, but after
1153
+ splitting we have a partition with the same name).
1154
+ Only simple, non-partitioned partition can be split.
1155
+ </para>
1156
+ <note>
1157
+ <para>
1158
+ This command acquires an <literal>ACCESS EXCLUSIVE</literal> lock.
1159
+ This is a significant limitation, which limits the usage of this
1160
+ command with large partitioned tables under a high load.
1161
+ </para>
1162
+ </note>
1163
+ </listitem>
1164
+ </varlistentry>
1165
+
1124
1166
<varlistentry id="sql-altertable-merge-partitions">
1125
1167
<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
1168
@@ -1188,7 +1230,8 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1188
1230
All the forms of ALTER TABLE that act on a single table, except
1189
1231
<literal>RENAME</literal>, <literal>SET SCHEMA</literal>,
1190
1232
<literal>ATTACH PARTITION</literal>, <literal>DETACH PARTITION</literal>,
1191
- and <literal>MERGE PARTITIONS</literal> can be combined into
1233
+ <literal>SPLIT PARTITION</literal>, and <literal>MERGE PARTITIONS</literal>
1234
+ can be combined into
1192
1235
a list of multiple alterations to be applied together. For example, it
1193
1236
is possible to add several columns and/or alter the type of several
1194
1237
columns in a single command. This is particularly useful with large
@@ -1432,7 +1475,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM
1432
1475
<listitem>
1433
1476
<para>
1434
1477
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.
1478
+ or the name of split partition, or the name of the new merged partition.
1436
1479
</para>
1437
1480
</listitem>
1438
1481
</varlistentry>
@@ -1848,6 +1891,24 @@ ALTER TABLE measurement
1848
1891
DETACH PARTITION measurement_y2015m12;
1849
1892
</programlisting></para>
1850
1893
1894
+ <para>
1895
+ To split a single partition of the range-partitioned table:
1896
+ <programlisting>
1897
+ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2023 INTO
1898
+ (PARTITION sales_feb2023 FOR VALUES FROM ('2023-02-01') TO ('2023-03-01'),
1899
+ PARTITION sales_mar2023 FOR VALUES FROM ('2023-03-01') TO ('2023-04-01'),
1900
+ PARTITION sales_apr2023 FOR VALUES FROM ('2023-04-01') TO ('2023-05-01'));
1901
+ </programlisting></para>
1902
+
1903
+ <para>
1904
+ To split a single partition of the list-partitioned table:
1905
+ <programlisting>
1906
+ ALTER TABLE sales_list SPLIT PARTITION sales_all INTO
1907
+ (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'),
1908
+ PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'),
1909
+ PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv'));
1910
+ </programlisting></para>
1911
+
1851
1912
<para>
1852
1913
To merge several partitions into one partition of the target table:
1853
1914
<programlisting>
0 commit comments