All Products
Search
Document Center

Hologres:ALTER PARTITION TABLE

Last Updated:Mar 18, 2026

Use the ALTER TABLE statement to modify a partitioned table in Hologres. You can rename a partitioned table, attach an independent table as a child partition, or detach an existing child partition from its parent.

Syntax

ALTER TABLE [IF EXISTS] table_name RENAME TO new_table_name;
ALTER TABLE [IF EXISTS] table_name ATTACH PARTITION new_partition_name FOR VALUES IN (<string_literal>);
ALTER TABLE [IF EXISTS] table_name DETACH PARTITION partition_name;

Parameters

ParameterDescription
RENAMERenames the partitioned table.
ATTACH PARTITION new_partition_name FOR VALUES IN (<string_literal>)Attaches an existing table to a partitioned table as a child partition. The table must match the partition policy and partition key of the parent table. Additional constraints apply — see Limits.
DETACH PARTITION partition_nameDetaches a partition from a partitioned table. The detached partition becomes a standalone, independent table with no relationship to the former parent.

Limits

Column requirements

Before attaching a table, verify that it meets these column requirements:

  • The table must have the same number of columns as the parent partitioned table.

  • The data type of each column must match the corresponding column in the parent table.

  • The table must satisfy all NOT NULL constraints defined on the parent table. For a list partition that does not accept NULL values, add a NOT NULL constraint to the partition key column, unless the primary key is an expression.

Property rules when attaching a child partition

When you attach a table to a partitioned table, Hologres validates property compatibility between the child table and the parent table at attach time. If a required property does not match, the attach operation fails immediately and returns an error.

Three compatibility rules apply:

  • Must be consistent: The child table property must match the parent table property. If it does not match, the attach operation fails and you must create a new child table with the correct property value.

  • Need not be consistent: The child table property can differ from the parent table property. If the property is not specified on the child table, the child table inherits the value from the parent table. If the property is specified, the specified value is kept.

  • Must include indexed columns of the parent table: The child table must index all columns that the parent table indexes. The child table can index additional columns that the parent table does not index.

The following table lists all properties and the rules that apply when attaching a child partition:

CategoryPropertyDescriptionInherited by CREATE TABLE PARTITION OFRule when attachingRetained after detaching
Table propertyorientationStorage format of the tableYesMust be consistentYes
Table propertytable_groupTable group that the table belongs to; also determines the shard countYesMust be consistentYes
Table propertytime_to_live_in_secondsTime-to-live (TTL) period of the tableYesNeed not be consistent. If not specified on the child table, inherits from the parent table. If specified, the specified value is kept.Yes
Indexprimary keyPrimary key of the tableYesMust be consistentYes
Indexdistribution keyDistribution key of the tableYesMust be consistentYes
Indexclustering_keyClustered index: specifies columns and their storage orderYesMust be consistentYes
Indexevent_time_columnSegment key of the tableYesMust be consistentYes
Indexbitmap_columnsBitmap indexes of the tableYesMust include indexed columns of the parent tableYes
Indexdictionary_encoding_columnsDictionary-encoded columns of the tableYesMust include indexed columns of the parent tableYes
Indexbinlog_levelWhether binary logging is enabledYesMust be consistentYes
Indexproxima_vectorsVector indexes of the tableYesMust include indexed columns of the parent tableYes
Column constraintnullableNOT NULL constraintYesMust be consistentYes
Column constraintdefault valueDefault value constraintYesMust be consistentYes

Examples

Basic operations

The following examples show how to rename a partitioned table, attach a partition, and detach a partition.

-- Rename a partitioned table.
alter table holo_test rename to my_holo_test;

-- Attach the table named my_table as a partition of the table named holo_table.
alter table holo_table attach partition my_table for values in ('2015');

-- Detach the child partitioned table holo_test from the parent partitioned table all_test.
alter table all_test detach partition holo_test;

Replace an existing child partition

Use a transaction to atomically replace an existing child partition with new data. This pattern detaches the old partition, renames it as a backup, renames the new table to take its place, and then attaches the new partition — all within a single transaction block.

Step 1: Create and populate the replacement table.

-- Create a temporary table.
begin;
drop table if exists "table_20210101_new";
CREATE TABLE "table_20210101_new" (
  "colA" integer NOT NULL,
  "colB" text NOT NULL,
  "colC" numeric(38,10) NOT NULL,
  "ds" text NOT NULL,
  "process_time" timestamptz NOT NULL DEFAULT now()
);
call set_table_property('table_20210101_new', 'orientation','column');
call set_table_property('table_20210101_new', 'distribution_key','"colA"');
call set_table_property('table_20210101_new', 'event_time_column','process_time');
commit;

--- Import data to the temporary table.
insert into "table_20210101_new" select * from ...;

Step 2: Swap the old partition for the new one.

--- Replace an existing child partitioned table with the temporary table.
begin;
-- Detach an existing child partitioned table from the parent partitioned table and make the child partitioned table an independent table.
ALTER TABLE table_parent DETACH PARTITION table_20210101;
-- Rename the independent table.
ALTER TABLE table_20210101 RENAME to table_20210101_backup;
-- Rename the temporary table as the original child partitioned table.
ALTER TABLE table_20210101_new RENAME to table_20210101;
-- Attach the new child partitioned table to the parent partitioned table.
ALTER TABLE table_parent ATTACH PARTITION table_20210101 FOR VALUES in ("20210101");
commit;