On this page

    Altering Apache Iceberg Tables

    The ALTER command updates an Iceberg table’s schema in a new snapshot.

    Syntax
    ALTER TABLE <table_path>.<table_name> 
    [ ADD COLUMNS (<columnName1> <dataType1>(<size1>), <columnName2> <dataType2>(<size2>), ...) ]
    | [ DROP COLUMN <columnName> ]
    | [ ALTER COLUMN <sourceColumnName> <sourceColumnName> <newDataType>(<size>) ]
    | [ MODIFY COLUMN <sourceColumnName> <sourceColumnName> <newDataType>(<size>) ]
    | [ REFRESH METADATA ]
    

    Parameters

    <table_path>

    String

    The path in which the table is located.


    <table_name>

    String

    The name of the table that you want to query.


    [ ADD COLUMNS (<columnName1> <dataType1>(<size1>), <columnName2> <dataType2>(<size2>), ...) ]

    String

    Creates one or more columns that have the specified names, data types, and character limits.


    [ DROP COLUMN <columnName> ]

    String

    Drops the specified column. Because this cannot be undone, ensure that you’ve secured a backup or snapshot of your database.


    [ ALTER COLUMN <sourceColumnName> <sourceColumnName> <newDataType>(<size>) ]

    String

    Changes the data type for a specified column. Only three types of type changes are allowed:

    • int to long
    • float to double
    • decimal(P, S) to decimal(P', S), if you are widening the precision

    [ MODIFY COLUMN <sourceColumnName> <sourceColumnName> <newDataType>(<size>) ]

    String

    This option has the same effect as ALTER COLUMN.


    [ REFRESH METADATA ]

    String

    Refreshes the metadata for the table.

    Examples

    Adding a column
    ALTER TABLE myTable ADD COLUMNS (address VARCHAR)
    
    Changing the data type of a column to BIGINT
    ALTER TABLE myTable ALTER COLUMN id id BIGINT