Updated on 2026-11-06 GMT+08:00

ALTER TABLE

Function

ALTER TABLE is a unique syntax within Aura. It modifies metadata information for tables on LakeFormation, enabling adjustments to table structures or attributes.

Constraints

  • The ADD COLUMNS, DROP COLUMNS, COLUMN RENAME, and ALTER COLUMN syntaxes take effect only for Iceberg tables.
  • Column position operations and complex type field operations apply exclusively to Iceberg tables.
  • Only Iceberg tables support creating and deleting branches and tags.
  • External tables do not support ALTER TABLE.

Syntax

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
ALTER TABLE table_name DROP PARTITIONS ( col_name = col_value [, ... ] ) [, ... ];
ALTER TABLE table_name ADD COLUMN col_name col_type [ COMMENT col_comment ] [ FIRST |  BEFORE col_name | AFTER col_name ] [, ... ];
ALTER TABLE table_name DROP COLUMNS ( col_name [, ... ] );
ALTER TABLE table_name RENAME COLUMN col_name TO col_name_new;
ALTER TABLE table_name ALTER COLUMN col_name [ TYPE col_type ] [ COMMENT col_comment ] [ FIRST |  BEFORE col_name | AFTER col_name ] [, ... ];
ALTER TABLE table_name RENAME TO table_name_new;
ALTER TABLE table_name SET TABLEPROPERTIES ( option_key = option_value [, ... ] );
ALTER TABLE table_name UNSET TABLEPROPERTIES ( option_key [, ... ] );
ALTER TABLE table_name UPDATE COLUMNS;
ALTER TABLE table_name ADD PARTITION COLUMN transform [, ...];
ALTER TABLE table_name DROP PARTITION COLUMN transform [, ...];
ALTER TABLE table_name SET PARTITION COLUMN transform [, ...];
ALTER TABLE table_name OWNER TO USER RoleId;
ALTER TABLE table_name OWNER TO USER GROUP RoleId;
ALTER TABLE table_name CREATE [OR REPLACE] BRANCH [IF NOT EXISTS] <branch_name>[AS OF VERSION <snapshot_id>][RETAIN <int> { DAYS | HOURS | MINUTES }][WITH SNAPSHOT RETENTION  { minSnapshotsToKeep | maxSnapshotAge | minSnapshotsToKeep maxSnapshotAge }] minSnapshotsToKeep ::= <int> SNAPSHOTS maxSnapshotAge ::= <int> { DAYS | HOURS | MINUTES }
ALTER TABLE table_name CREATE [OR REPLACE] TAG [IF NOT EXISTS] <tag_name>[AS OF VERSION <snapshot_id>][RETAIN <int> { DAYS | HOURS | MINUTES }]
ALTER TABLE table_name DROP { BRANCH [IF EXISTS] <branch_name> | TAG [IF EXISTS] <tag_name> }
The transform is as follows:
col_name | year(col_name) | month(col_name) | day(col_name) | hour(col_name)| truncate(width, col_name) | bucket(bucket_num, col_name)

Parameter Description

In the ALTER TABLE syntax, the parameter specifications are the same as those for table creation.

Examples

Add the sales bigint column to the test_table table.

1
ALTER TABLE test_table ADD COLUMN sales bigint COMMENT 'factory sales volume';

Rename the sales column in the test_table table to my_sales.

1
ALTER TABLE test_table RENAME COLUMN sales TO my_sales;

Change the type of the my_sales column in the test_table table to String.

1
ALTER TABLE test_table ALTER COLUMN my_sales TYPE text COMMENT 'factory sales volume';

Delete the my_sales column from the test_table table.

1
ALTER TABLE test_table DROP COLUMNS ( my_sales );

Rename the test_table table to factory_info.

1
ALTER TABLE test_table RENAME TO factory_info;

Enable the hoodie.metadata.enable parameter in the factory_info table.

1
ALTER TABLE factory_info SET TABLEPROPERTIES ( 'hoodie.metadata.enable' = 'true' );

Restore the parameters in the factory_info table.

1
ALTER TABLE factory_info UNSET TABLEPROPERTIES ( 'hoodie.metadata.enable' );

Synchronize the partition information of the factory_info table.

1
ALTER TABLE factory_info UPDATE COLUMNS;