view

Turns a subquery into a table. The function implements views (see CREATE VIEW). The resulting table does not store data, but only stores the specified SELECT query. When reading from the table, ClickHouse executes the query and deletes all unnecessary columns from the result.

Syntax

  1. view(subquery)

Arguments

  • subquerySELECT query.

Returned value

  • A table.

Example

Input table:

  1. ┌─id─┬─name─────┬─days─┐
  2. 1 January 31
  3. 2 February 29
  4. 3 March 31
  5. 4 April 30
  6. └────┴──────────┴──────┘

Query:

  1. SELECT * FROM view(SELECT name FROM months);

Result:

  1. ┌─name─────┐
  2. January
  3. February
  4. March
  5. April
  6. └──────────┘

You can use the view function as a parameter of the remote and cluster table functions:

  1. SELECT * FROM remote(`127.0.0.1`, view(SELECT a, b, c FROM table_name));
  1. SELECT * FROM cluster(`cluster_name`, view(SELECT a, b, c FROM table_name));

See Also