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

# ALTER TABLE ... MODIFY REFRESH fails on an APPEND refreshable materialized view

> Changing the schedule of an APPEND refreshable materialized view fails with NOT_IMPLEMENTED unless the statement repeats APPEND. Switching modes needs CREATE OR REPLACE.

`ALTER TABLE ... MODIFY REFRESH` replaces the whole `REFRESH` clause of a [refreshable materialized view](https://clickhouse.com/docs/concepts/features/materialized-views/refreshable-materialized-view.md), and the refresh mode is part of that clause. If the view was created with `APPEND` and the new clause does not repeat it, ClickHouse treats the statement as an attempt to remove `APPEND`, which is not supported:

```text theme={null}
Code: 48. DB::Exception: Changing APPEND or INCREMENTAL is not supported. (NOT_IMPLEMENTED)
```

To change the schedule, repeat `APPEND` at the end of the new `REFRESH` clause. To change the mode itself, recreate the view with `CREATE OR REPLACE MATERIALIZED VIEW`.

## Reproduce the error

```sql theme={null}
CREATE DATABASE demo;

CREATE TABLE demo.events (id UInt64, message String) ENGINE = MergeTree ORDER BY id;
CREATE TABLE demo.events_copy (id UInt64, message String) ENGINE = MergeTree ORDER BY id;
INSERT INTO demo.events VALUES (1, 'first'), (2, 'second');

CREATE MATERIALIZED VIEW demo.events_copy_mv
REFRESH EVERY 1 HOUR APPEND TO demo.events_copy
AS SELECT id, message FROM demo.events;

ALTER TABLE demo.events_copy_mv MODIFY REFRESH EVERY 3 HOUR;
```

```text theme={null}
Code: 48. DB::Exception: Changing APPEND or INCREMENTAL is not supported. (NOT_IMPLEMENTED)
```

The failed statement changes nothing: the view keeps its schedule. The opposite direction fails with the same message: you cannot add `APPEND` to a view that was created without it. The [reference](https://clickhouse.com/docs/reference/statements/alter/view.md#alter-table--modify-refresh-statement) describes this limitation as "adding or removing `APPEND` is not supported".

## Repeat the mode in the new clause

```sql theme={null}
ALTER TABLE demo.events_copy_mv MODIFY REFRESH EVERY 3 HOUR APPEND;

SHOW CREATE TABLE demo.events_copy_mv;
```

```text theme={null}
CREATE MATERIALIZED VIEW demo.events_copy_mv
REFRESH EVERY 3 HOUR APPEND TO demo.events_copy
(
    `id` UInt64,
    `message` String
)
DEFINER = default SQL SECURITY DEFINER
AS SELECT
    id,
    message
FROM demo.events
```

The same rule applies to everything else in the clause, because the statement replaces all of it:

* A view created with `APPEND INCREMENTAL` needs both keywords. `APPEND` alone is rejected with the same message.
* The mode comes last, after `RANDOMIZE FOR`, `DEPENDS ON` and `SETTINGS`, as in `MODIFY REFRESH EVERY 3 HOUR RANDOMIZE FOR 10 MINUTE SETTINGS refresh_retries = 5 APPEND`. If you write `SETTINGS` after `APPEND`, the refresh settings are read as query settings and the statement fails with `Unknown setting 'refresh_retries'. (UNKNOWN_SETTING)`.
* A view created with `SETTINGS all_replicas = 1` has to repeat that setting. Otherwise the statement fails with `Altering setting 'all_replicas' is not supported. (NOT_IMPLEMENTED)`.
* `RANDOMIZE FOR`, `DEPENDS ON` and the other refresh settings that you leave out are removed or reset to their defaults without an error.

[`system.view_refreshes`](https://clickhouse.com/docs/reference/system-tables/view_refreshes) has no column for the refresh mode. Use `SHOW CREATE TABLE` to see the current `REFRESH` clause of a view before you modify it.

## Switch between the modes

A view cannot change its mode in place. Replace its definition with [`CREATE OR REPLACE MATERIALIZED VIEW`](https://clickhouse.com/docs/reference/statements/create/view#create-or-replace-materialized-view). When the view writes to a table named in the `TO` clause, the statement replaces the view only, and the target table keeps its rows.

What happens to these rows afterwards depends on the new mode. A view without `APPEND` replaces the whole content of its target table on every refresh, including rows that the view did not write:

```sql theme={null}
INSERT INTO demo.events_copy VALUES (999, 'inserted by hand');

CREATE OR REPLACE MATERIALIZED VIEW demo.events_copy_mv
REFRESH EVERY 3 HOUR TO demo.events_copy
AS SELECT id, message FROM demo.events;

SYSTEM WAIT VIEW demo.events_copy_mv;

SELECT * FROM demo.events_copy ORDER BY id;
```

```text theme={null}
   ┌─id─┬─message─┐
1. │  1 │ first   │
2. │  2 │ second  │
   └────┴─────────┘
```

The first refresh starts as soon as the view is created, and it replaced the rows appended earlier and the row inserted by hand. In the other direction, a view with `APPEND` adds the full result of its `SELECT` on every refresh, so rows are duplicated unless the `SELECT` only returns new rows. Add `EMPTY` to the `CREATE OR REPLACE` statement to skip the immediate first refresh.

A view without a `TO` clause stores its rows in an inner table, and `CREATE OR REPLACE` drops that table together with the old view.

## Related pages

* [`ALTER TABLE ... MODIFY REFRESH`](https://clickhouse.com/docs/reference/statements/alter/view#alter-table--modify-refresh-statement)
* [Refreshable materialized view: syntax, modes and refresh settings](https://clickhouse.com/docs/reference/statements/create/view.md#refreshable-materialized-view)
* [What happens to refreshable materialized views when the server restarts](https://clickhouse.com/docs/resources/support-center/knowledge-base/materialized-views/what-happens-to-refreshable-materialized-views-when-the-server-restarts.md)
