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

ALTER Statement

Overview

The ALTER statement is used to modify the definition of an object that has been registered with the catalog, including tables, views, databases, functions, and catalogs. You can use the ALTER statement to perform schema evolution, modify attributes, and rename objects without rebuilding them.

Application Scenarios

  • Schema evolution: When service requirements change, you can use ALTER TABLE ADD/DROP COLUMN to adjust the table structure online without rebuilding the table.
  • Parameter tuning: To adjust connector configuration parameters during job runtime, use ALTER TABLE SET to modify the WITH attributes.
  • Object management: Renames tables or views to correct non-standard naming issues.

Notes and Constraints

  • By default, columns added using ALTER TABLE are appended to the end of the table. Specifying the position of a column is not supported.
  • When modifying a watermark or primary key constraint, ensure that the modification is compatible with the existing column definitions.
  • The attributes that can be modified using ALTER DATABASE depend on the catalog implementation. Different catalogs support different attributes.
  • ALTER VIEW only supports renaming the view and modifying its attributes. It does not support modifying the query definition of the view.
  • Executing ALTER on a table that is currently being used by a job may cause the job to behave abnormally. It is recommended that the ALTER operation be performed after the job has been stopped.
  • ALTER TABLE only modifies metadata. Whether the physical table structure can be modified depends on the connector implementation.

Syntax Structure

ALTER TABLE

-- Rename a table.

ALTER TABLE [catalog_name.][db_name.]table_name RENAME TO new_table_name;

-- Modify table attributes.

ALTER TABLE [catalog_name.][db_name.]table_name SET (key1=val1, key2=val2, ...);

-- Add a column.

ALTER TABLE [catalog_name.][db_name.]table_name ADD (col_name col_type [COMMENT col_comment], ...);

-- Drop a column.

ALTER TABLE [catalog_name.][db_name.]table_name DROP (col_name, ...);

-- Add a watermark.

ALTER TABLE [catalog_name.][db_name.]table_name ADD WATERMARK FOR rowtime_col AS watermark_expr;

-- Drop a watermark.

ALTER TABLE [catalog_name.][db_name.]table_name DROP WATERMARK;

-- Add a primary key.

ALTER TABLE [catalog_name.][db_name.]table_name ADD PRIMARY KEY (col_name, ...) NOT ENFORCED;

-- Drop a primary key.

ALTER TABLE [catalog_name.][db_name.]table_name DROP PRIMARY KEY;

-- Rename a column.

ALTER TABLE [catalog_name.][db_name.]table_name RENAME col_name TO new_col_name;

-- Modify a column type.

ALTER TABLE [catalog_name.][db_name.]table_name MODIFY (col_name new_col_type [COMMENT col_comment], ...);

ALTER VIEW

-- Rename a view.

ALTER VIEW [catalog_name.][db_name.]view_name RENAME TO new_view_name;

-- Alter view attributes.

ALTER VIEW [catalog_name.][db_name.]view_name SET (key1=val1, key2=val2, ...);

ALTER DATABASE

-- Alter database attributes.

ALTER DATABASE [catalog_name.]db_name SET (key1=val1, key2=val2, ...);

ALTER FUNCTION

-- Alter the function definition.

ALTER [SYSTEM] FUNCTION [IF EXISTS] [catalog_name.][db_name.]function_name
AS class_identifier
[LANGUAGE JAVA|SCALA|PYTHON];

ALTER CATALOG

-- Alter catalog attributes.

ALTER CATALOG catalog_name SET (key1=val1, key2=val2, ...);

Usage Example

Example: Add columns and alter attributes using ALTER TABLE.

-- ALTER TABLE paimon_append_source ADD (email STRING COMMENT 'User email address');
-- ALTER TABLE paimon_append_source SET ('rows-per-second' = '200');