All Products
Search
Document Center

ApsaraDB for ClickHouse:CREATE VIEW

Last Updated:Mar 28, 2026

Use CREATE VIEW to create a normal view in ApsaraDB for ClickHouse. ApsaraDB for ClickHouse supports two view types: normal view (this topic) and materialized view.

Syntax

CREATE VIEW [IF NOT EXISTS] [db.]view_name [ON CLUSTER cluster] AS SELECT ...

Parameters

ParameterDescription
IF NOT EXISTSSkip view creation if a view with the same name already exists.
dbDatabase name. Defaults to the current database.
view_nameName of the view.
ON CLUSTER clusterCreate the view on every node in the cluster.
SELECT ...The query that defines the view. Supports DISTINCT, GROUP BY, ORDER BY, and LIMIT.
In ApsaraDB for ClickHouse, set ON CLUSTER to default. For example: ON CLUSTER default.

Create a view

The following example creates a source table, creates a view over it, inserts data, and then queries the view.

  1. Create the source table.

    CREATE TABLE test ON CLUSTER default (
      id   Int32,
      name String
    ) ENGINE = MergeTree()
    ORDER BY (id);
  2. Create a view based on the source table.

    CREATE VIEW test_view ON CLUSTER default AS SELECT * FROM test;
  3. Insert data into the source table.

    INSERT INTO test VALUES (1, 'a'), (2, 'b'), (3, 'c');
  4. Query the view.

    SELECT * FROM test_view;

    Expected output:

    id│name
    ─│──
     1│ a
     2│ b
     3│ c

References