mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-11 17:02:25 +00:00
1.4 KiB
1.4 KiB
slug | sidebar_position | sidebar_label |
---|---|---|
/en/sql-reference/statements/alter/view | 50 | VIEW |
ALTER TABLE … MODIFY QUERY Statement
You can modify SELECT
query that was specified when a materialized view was created with the ALTER TABLE … MODIFY QUERY
statement. Use it when the materialized view was created without the TO [db.]name
clause. The allow_experimental_alter_materialized_view_structure
setting must be enabled.
If a materialized view uses the TO [db.]name
construction, you must DETACH the view, run ALTER TABLE query for the target table, and then ATTACH the previously detached (DETACH
) view.
Example
CREATE TABLE src_table (`a` UInt32) ENGINE = MergeTree ORDER BY a;
CREATE MATERIALIZED VIEW mv (`a` UInt32) ENGINE = MergeTree ORDER BY a AS SELECT a FROM src_table;
INSERT INTO src_table (a) VALUES (1), (2);
SELECT * FROM mv;
┌─a─┐
│ 1 │
│ 2 │
└───┘
ALTER TABLE mv MODIFY QUERY SELECT a * 2 as a FROM src_table;
INSERT INTO src_table (a) VALUES (3), (4);
SELECT * FROM mv;
┌─a─┐
│ 6 │
│ 8 │
└───┘
┌─a─┐
│ 1 │
│ 2 │
└───┘
ALTER LIVE VIEW Statement
ALTER LIVE VIEW ... REFRESH
statement refreshes a Live view. See Force Live View Refresh.