Skip to main content
ALTER TABLE ... RENAME COLUMN cannot add or remove a dot in a column name. ClickHouse reads the part of the name before the first dot as the name of a Nested structure, and a rename is not allowed to move a column into or out of such a structure. To get rid of the dot, add a column with the new name, copy the data into it, and drop the old column.

The error

Why this happens

A column name with a dot is valid. It is how the elements of a Nested column are stored (payload Nested(status String) becomes the column payload.status of type Array(String)), and ingestion tools that flatten nested JSON often produce such names as well. Because of that, RENAME COLUMN treats payload as the name of a nested structure, whatever the type of the column is:
  • Renaming within the same prefix works: payload.status to payload.state.
  • Renaming to another prefix fails with Cannot rename column from one nested name to another.
  • Renaming between a name with a dot and a name without one fails with the error above.
This is described in the limitations of ALTER TABLE ... COLUMN.

Copy the data to a new column

Add the new column with the old column as its DEFAULT expression:
This changes only the table metadata. From now on, reads of payload_status return the value of payload.status, and an INSERT that still writes only payload.status stores the same value in both columns. You can switch readers and writers to the new name at your own pace. Then write the values of the new column into the existing data parts:
MATERIALIZE COLUMN is a mutation: it rewrites the column in every part and runs in the background by default. With mutations_sync = 2 the statement returns only when the mutation has finished on all replicas. If you run it without this setting, wait until system.mutations shows it as done:
Do not continue before the mutation is done. Until a data part is rewritten, the values of payload_status in it exist only as an expression over payload.status. If you remove the DEFAULT expression earlier, payload_status is empty for the rows of such parts.
When the mutation is done and nothing writes to the old column any more, remove the dependency between the two columns and drop the old one:
Without the REMOVE DEFAULT step, the DROP COLUMN is rejected, because payload_status still depends on the old column (error ILLEGAL_COLUMN).

If the column is part of the sorting key

A column that is used in the ORDER BY, PRIMARY KEY or PARTITION BY expression cannot be dropped, so the last step of the procedure above fails:
You have two options:
After the exchange, events_by_status_new holds the old data and can be dropped. Rows inserted into the old table after the INSERT INTO ... SELECT has started are not copied, and after the exchange they are only in the table that you are about to drop. Stop writes before the copy starts and resume them only after EXCHANGE TABLES. From then on, an INSERT that names the column has to use payload_status.

Avoid the problem in new tables

If you control the ingestion pipeline, configure it to join flattened keys with another separator, such as _. Since version 26.4, a MergeTree table can also be created with the setting share_nested_offsets = 0. In such a table a dot in a column name has no special meaning, and the rename works:
The setting can only be chosen when the table is created. ALTER TABLE ... MODIFY SETTING share_nested_offsets = 0 on an existing table fails with Setting 'share_nested_offsets' is readonly for storage 'MergeTree'.