Alter Table Partition

Important

This documentation has been retired and might not be updated. The products, services, or technologies mentioned in this content are no longer supported. See ALTER TABLE.

Add partition

ALTER TABLE table_name ADD [IF NOT EXISTS]
    (PARTITION part_spec [LOCATION path], ...)

part_spec:
    : (part_col_name1=val1, part_col_name2=val2, ...)

Add partitions to the table, optionally with a custom location for each partition added. This is supported only for tables created using the Hive format. However, beginning with Spark 2.1, Alter Table Partitions is also supported for tables defined using the datasource API.

IF NOT EXISTS

If the specified partitions already exist, nothing happens.

Change partition

ALTER TABLE table_name PARTITION part_spec RENAME TO PARTITION part_spec

part_spec:
    : (part_col_name1=val1, part_col_name2=val2, ...)

Change the partitioning field values of a partition. This operation is allowed only for tables created using the Hive format.

Drop partition

ALTER TABLE table_name DROP [IF EXISTS] (PARTITION part_spec, ...)
part_spec:
    : (part_col_name1=val1, part_col_name2=val2, ...)

Drop a partition from a table or view. This operation is allowed only for tables created using the Hive format.

IF EXISTS

If the specified partition does not exists, nothing happens.

Set partition location

ALTER TABLE table_name PARTITION part_spec SET LOCATION path

part_spec:
    : (part_col_name1=val1, part_col_name2=val2, ...)

Set the location of the specified partition. Setting the location of individual partitions is allowed only for tables created using the Hive format.