alter Verified current stable Not installed? Data Processing

Alter / Add Partition To Table

Add Partition To Table

Adds a new partition to an existing table based on a specified key.

$
Terminal
alter table <table_name> add partition (<partition_spec>);

When To Use

When scaling out a table architecture to accommodate increasing data volumes.

Pro Tip

Monitor partition sizes closely; excessively large partitions can severely hinder performance.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
alter table <table_name> add partition (<partition_spec>);

Anatomy of Output

Understanding the result

Query OK, 0 rows affected (0.05 sec) Operation Result

Indicates that the partitioning has been successfully modified.

ALTER TABLE `existing_table` ADD PARTITION (partition_spec); Executed Command

Outputs command that confirms addition of partition.

Troubleshooting

Common pitfalls

ERROR 1063 (42000): Duplicate partition name

Solution: Ensure partition names are unique within the table.

ERROR 1492 (HY000): Invalid partition specification

Solution: Review the syntax and properties of the partition you're trying to add.

ERROR 1048 (23000): Column 'column_name' cannot be null

Solution: Ensure all required fields in the new partition are populated.

Command Breakdown

What each part is doing

alter
Base Command
The executable that performs this operation. Here it runs Alter before the shell applies any redirect operators.
<table_name>
table name
The value supplied for table name.
<partition_spec>
partition spec
The value supplied for partition spec.

Alternative Approaches

Comparable commands in other tools

Alternative data processing tools for the same job.