DOCAPI-7719: Columns matcher docs (#6831)

* Typo fix.

* DOCAPI-7719: Docs

* DOCAPI-7719: Text.

* DOCAPI-7719: Text.

* DOCAPI-7719: Update.

* DOCAPI-7719: Update.
This commit is contained in:
BayoNet 2019-09-25 02:07:52 +03:00 committed by alexey-milovidov
parent 60d74a5e55
commit c3c3f3829e
2 changed files with 59 additions and 7 deletions

View File

@ -66,7 +66,7 @@ mysql> select * from test;
1 row in set (0,00 sec)
```
Table in ClickHouse, retrieving data from the MySQL table:
Table in ClickHouse, retrieving data from the MySQL table created above:
```sql
CREATE TABLE mysql_table
@ -77,7 +77,7 @@ CREATE TABLE mysql_table
ENGINE = MySQL('localhost:3306', 'test', 'test', 'bayonet', '123')
```
```sql
SELECT * FROM mysql_table6
SELECT * FROM mysql_table
```
```text
┌─float_nullable─┬─int_id─┐

View File

@ -962,12 +962,64 @@ Running a query may use more memory than 'max_bytes_before_external_sort'. For t
External sorting works much less effectively than sorting in RAM.
### SELECT Clause
### SELECT Clause {#select-select}
[Expressions](syntax.md#syntax-expressions) that specified in the `SELECT` clause are analyzed after the calculations for all the clauses listed above are completed. More specifically, expressions are analyzed that are above the aggregate functions, if there are any aggregate functions. The aggregate functions and everything below them are calculated during aggregation (`GROUP BY`). These expressions work as if they are applied to separate rows in the result.
If you want to get all columns in the result, use the asterisk (`*`) symbol. For example, `SELECT * FROM ...`.
To match some columns in the result by a [re2](https://en.wikipedia.org/wiki/RE2_(software)) regular expression, you can use the `COLUMNS` expression.
```sql
COLUMNS('regexp')
```
For example, consider the table:
```sql
CREATE TABLE default.col_names (aa Int8, ab Int8, bc Int8) ENGINE = TinyLog
```
The following query selects data from all the columns containing the `a` symbol in their name.
```sql
SELECT COLUMNS('a') FROM col_names
```
```text
┌─aa─┬─ab─┐
│ 1 │ 1 │
└────┴────┘
```
You can use multiple `COLUMNS` expressions in a query, also you can apply functions to it.
For example:
```sql
SELECT COLUMNS('a'), COLUMNS('c'), toTypeName(COLUMNS('c')) FROM col_names
```
```text
┌─aa─┬─ab─┬─bc─┬─toTypeName(bc)─┐
│ 1 │ 1 │ 1 │ Int8 │
└────┴────┴────┴────────────────┘
```
Be careful when using functions because the `COLUMN` expression returns variable number of columns, and, if a function doesn't support this number of arguments, ClickHouse throws an exception.
For example:
```sql
SELECT COLUMNS('a') + COLUMNS('c') FROM col_names
```
```text
Received exception from server (version 19.14.1):
Code: 42. DB::Exception: Received from localhost:9000. DB::Exception: Number of arguments for function plus doesn't match: passed 3, should be 2.
```
In this example, `COLUMNS('a')` returns two columns `aa`, `ab`, and `COLUMNS('c')` returns the `bc` column. The `+` operator can't apply to 3 arguments, so ClickHouse throws an exception with the message about it.
Columns that matched by the `COLUMNS` expression can be in different types. If `COLUMNS` doesn't match any columns and it is the single expression in `SELECT`, ClickHouse throws an exception.
The expressions specified in the SELECT clause are analyzed after the calculations for all the clauses listed above are completed.
More specifically, expressions are analyzed that are above the aggregate functions, if there are any aggregate functions.
The aggregate functions and everything below them are calculated during aggregation (GROUP BY).
These expressions work as if they are applied to separate rows in the result.
### DISTINCT Clause {#select-distinct}