Jaa


ALTER TABLE … PARTITION

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Adds, drops, renames, or recovers partitions of a table.

Managing partitions is not supported for Delta Lake tables.

Syntax

ALTER TABLE table_name
   { ADD PARTITION clause |
     DROP PARTITION clause |
     PARTITION SET LOCATION clause |
     RENAME PARTITION clause |
     RECOVER PARTITIONS clause }

ADD PARTITION clause

Adds one or more partitions to the table.

Managing partitions is not supported for Delta Lake tables.

Syntax

ADD [IF NOT EXISTS] { PARTITION clause [ LOCATION path ] } [...]

Parameters

  • IF NOT EXISTS

    An optional clause directing Azure Databricks to ignore the statement if the partition already exists.

  • PARTITION clause

    A partition to be added. The partition keys must match the partitioning of the table and be associated with values. If the partition already exists an error is raised unless IF NOT EXISTS has been specified.

  • LOCATION path

    path must be a STRING literal representing an optional location pointing to the partition.

    If no location is specified the location will be derived from the location of the table and the partition keys.

    If there are files present at the location they populate the partition and must be compatible with the data_source of the table and its options.

DROP PARTITION clause

Drops one or more partitions from the table, optionally deleting any files at the partitions’ locations.

Managing partitions is not supported for Delta Lake tables.

Syntax

DROP [ IF EXISTS ] PARTITION clause [, ...] [PURGE]

Parameters

RENAME PARTITION clause

Replaces the keys of a partition.

Managing partitions is not supported for Delta Lake tables.

Syntax

from_partition_clause RENAME TO to_partition_clause

Parameters

RECOVER PARTITIONS clause

This clause does not apply to Delta Lake tables.

Instructs Azure Databricks to scan the table’s location and add any files to the table which have been added directly to the filesystem.

Managing partitions is not supported for Delta Lake tables.

Syntax

RECOVER PARTITIONS

Parameters

None

PARTITION SET LOCATION clause

Moves the location of a partition.

Managing partitions is not supported for Delta Lake tables.

Syntax

PARTITION clause SET LOCATION path

Parameters

  • PARTITION clause

    Identifies the partition for which the location will to be changed.

  • LOCATION path

    path must be a STRING literal. Specifies the new location for the partition.

    Files in the original location will not be moved to the new location.

Examples

See ALTER TABLE examples.