v.24.9Improvement

CREATE TABLE AS now supports PRIMARY KEY and ORDER BY for MergeTree engines

CREATE TABLE AS now copies PRIMARY KEY, ORDER BY, and similar clauses. Now it supports only for MergeTree family of table engines. #69076 (sakulali).
The CREATE TABLE AS statement in ClickHouse now copies PRIMARY KEY, ORDER BY, and similar clauses when creating tables. This feature currently supports only the MergeTree family of table engines.

Why it matters

This feature simplifies the process of duplicating tables by automatically carrying over key structural definitions such as PRIMARY KEY and ORDER BY clauses. It reduces manual effort and potential errors when creating similar tables based on existing table schemas, thereby improving developer productivity and consistency.

How to use it

When using CREATE TABLE AS with tables from the MergeTree family, the statement will automatically copy the original table's PRIMARY KEY, ORDER BY, and similar clauses. No additional parameters or flags are needed to enable this behavior.