CREATE VIEW
This section describes how to create a normal view in ClickHouse.
Creating a View
CREATE VIEW [IF NOT EXISTS] [db.]view_name [ON CLUSTER ClickHouse cluster name] AS SELECT ...
Parameter |
Description |
---|---|
db |
Name of the database. The default value is the selected database. |
view_name |
View name. |
[ON CLUSTER ClickHouse cluster name] |
This parameter specifies that a view is created on each node. The parameter format is ON CLUSTER ClickHouse cluster name. |
SELECT ... |
SELECT clause. When you insert data into the source table that is specified in the SELECT clause in the view, the inserted data is transformed by the SELECT query and the final result is inserted into the view. |
Examples:
- Create a source table.
create table DB.table1 ON CLUSTER default_cluster (id Int16,name String) ENGINE = MergeTree() ORDER BY (id);
- Create a view.
CREATE VIEW test_view ON CLUSTER default_cluster AS SELECT * FROM DB.table1;
- Insert data to the source table.
insert into DB.table1 values(1,'X'),(2,'Y'),(3,'Z');
- Query a view.
SELECT * FROM test_view;
- Delete a view.
drop table test_view ON CLUSTER default_cluster;
- If the table creation statement contains ON CLUSTER ClickHouse cluster name, run the following command to delete the table:
drop table Table name ON CLUSTER default_cluster;
- If the table creation statement does not contain ON CLUSTER ClickHouse cluster name, run the following command to delete the table:
drop table Table name;
- If the table creation statement contains ON CLUSTER ClickHouse cluster name, run the following command to delete the table:
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot