> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How to work around "CREATE AS SELECT is not supported with Replicated databases"

> CREATE TABLE ... AS SELECT with a replicated table engine is rejected in a Replicated database. Create the table with EMPTY AS SELECT and fill it with INSERT ... SELECT instead.

In a database with the [`Replicated`](https://clickhouse.com/docs/reference/engines/database-engines/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:

```sql theme={null}
CREATE TABLE events
(
    event_time DateTime,
    user_id UInt32,
    amount Decimal(10, 2)
)
ENGINE = ReplicatedMergeTree
ORDER BY (user_id, event_time);

INSERT INTO events VALUES
    ('2026-11-01 10:00:00', 1, 10.50),
    ('2026-11-01 11:30:00', 2, 4.25),
    ('2026-11-02 09:15:00', 1, 7.00),
    ('2026-11-02 18:45:00', 3, 12.75),
    ('2026-11-03 08:05:00', 2, 3.50);
```

Creating a second replicated table from a query is rejected:

```sql theme={null}
CREATE TABLE daily_totals
ENGINE = ReplicatedMergeTree
ORDER BY day
AS SELECT
    toDate(event_time) AS day,
    count() AS events,
    sum(amount) AS total
FROM events
GROUP BY day;
```

```text theme={null}
Code: 344. DB::Exception: CREATE AS SELECT is not supported with Replicated databases. Consider using separate CREATE and INSERT queries.. (SUPPORT_IS_DISABLED)
```

## 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:

```sql theme={null}
CREATE TABLE daily_totals
ENGINE = ReplicatedMergeTree
ORDER BY day
EMPTY AS SELECT
    toDate(event_time) AS day,
    count() AS events,
    sum(amount) AS total
FROM events
GROUP BY day;

SELECT name, type
FROM system.columns
WHERE database = currentDatabase() AND table = 'daily_totals';
```

```text theme={null}
   ┌─name───┬─type───────────┐
1. │ day    │ Date           │
2. │ events │ UInt64         │
3. │ total  │ Decimal(38, 2) │
   └────────┴────────────────┘
```

Then run the same query as an `INSERT ... SELECT`:

```sql theme={null}
INSERT INTO daily_totals
SELECT
    toDate(event_time) AS day,
    count() AS events,
    sum(amount) AS total
FROM events
GROUP BY day;

SELECT *
FROM daily_totals
ORDER BY day;
```

```text theme={null}
   ┌────────day─┬─events─┬─total─┐
1. │ 2026-11-01 │      2 │ 14.75 │
2. │ 2026-11-02 │      2 │ 19.75 │
3. │ 2026-11-03 │      1 │   3.5 │
   └────────────┴────────┴───────┘
```

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`](https://clickhouse.com/docs/reference/settings/session-settings/database-replicated#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](https://clickhouse.com/docs/products/cloud/features/infrastructure/shared-catalog.md#shared-database-engine).

## Related pages

* [`Replicated` database engine](https://clickhouse.com/docs/reference/engines/database-engines/replicated)
* [Create a table with a `SELECT` query](https://clickhouse.com/docs/reference/statements/create/table#from-select-query)
* [`INSERT INTO ... SELECT`](https://clickhouse.com/docs/reference/statements/insert-into#inserting-the-results-of-select)
