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 aReplicated database:
Create the table empty, then insert
Add theEMPTY keyword before AS SELECT. The table gets its structure from the query, and no data is loaded:
INSERT ... SELECT:
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
AReplicated 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, runSELECT name, engine FROM system.databases. - Tables with a non-replicated engine, for example
MergeTreeorMemory, can be created withAS SELECTin aReplicateddatabase. The database replicates only the table definition, so the data of such a table is not replicated. CREATE VIEWandCREATE MATERIALIZED VIEWwithoutPOPULATEare not affected.- The setting
database_replicated_allow_heavy_createdoes not lift this restriction. It only allowsCREATE MATERIALIZED VIEW ... POPULATEwith a replicated engine. - Databases in ClickHouse Cloud use the
Sharedengine, which supportsCREATE TABLE ... AS SELECT: see Shared catalog and shared database engine.