tencent cloud

Feedback

ALTER TABLE ADD COLUMNS

Last updated: 2024-08-07 17:14:57

    Description

    Supported engines: Presto and SparkSQL
    Applicable table: Native Iceberg tables and external tables
    Purpose: Change data table attributes.

    Standard Statement

    ALTER TABLE table_name
    [PARTITION
    (partition_col1_name = partition_col1_value
    [,partition_col2_name = partition_col2_value][,...])]
    ADD COLUMNS (col_name data_type) [RESTRICT | CASCADE]

    Parameter

    table_name: Name of the target table
    partition_col1_name: Partitioning column name
    partition_col1_value: Partitioning column value
    col_name: Name of the column to be added.
    data_type: Type of the column to be added.

    Example

    ALTER TABLE events ADD COLUMNS (eventowner string);
    
    ALTER TABLE events ADD COLUMNS (eventowner string) CASCADE;
    
    //The ALTER TABLE PARTITION ADD COLUMNS statement supports only native DLC tables.
    ALTER TABLE events PARTITION (year='2021') ADD COLUMNS (event string);
    
    Caution
    If you use the ROW FORMAT SERDE 'org.apache.hive.hcatalog.data.JsonSerDe' format during table creation, you cannot add columns after the table is created. If you use JsonSerDe to create a table, confirm the table structure if possible. If you must add columns, you can delete the existing table and create a new one.
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support