Skip to main content
In a database with the Replicated engine, CREATE TABLE ... AS SELECT fails with SUPPORT_IS_DISABLED when the new table uses a replicated table engine such as ReplicatedMergeTree. Split the statement in two: create an empty table with CREATE TABLE ... EMPTY AS SELECT, which takes the column names and types from the query, then load the data with INSERT ... SELECT.

The error

The examples use this table in a Replicated database:
Creating a second replicated table from a query is rejected:

Create the table empty, then insert

Add the EMPTY keyword before AS SELECT. The table gets its structure from the query, and no data is loaded:
Then run the same query as an INSERT ... SELECT:
The two statements are not atomic. If the INSERT fails, the table stays empty or partly filled, and you have to truncate or drop it before you retry. CREATE TABLE ... EMPTY AS SELECT is available since ClickHouse 22.7. You can also write the column list yourself in a regular CREATE TABLE and then run the INSERT ... SELECT.

What is and is not affected

A Replicated database writes every DDL statement to a log in ClickHouse Keeper, and each replica of the database executes it. A CREATE TABLE ... AS SELECT lasts as long as its data load, and ClickHouse does not accept such a long-running statement for a replicated table there, because it would hold up the DDL queue of the database.
  • The check applies to databases whose engine is Replicated. To see the engine, run SELECT name, engine FROM system.databases.
  • Tables with a non-replicated engine, for example MergeTree or Memory, can be created with AS SELECT in a Replicated database. The database replicates only the table definition, so the data of such a table is not replicated.
  • CREATE VIEW and CREATE MATERIALIZED VIEW without POPULATE are not affected.
  • The setting database_replicated_allow_heavy_create does not lift this restriction. It only allows CREATE MATERIALIZED VIEW ... POPULATE with a replicated engine.
  • Databases in ClickHouse Cloud use the Shared engine, which supports CREATE TABLE ... AS SELECT: see Shared catalog and shared database engine.