提交 77e10884 编写于 作者: D Dmitriy

Document union_default_mode setting

Задокументировал настройку union_default_mode.
上级 60aef3d5
......@@ -2423,4 +2423,83 @@ Possible values:
Default value: `0`.
## union_default_mode {#union-default-mode}
Sets a special mode for combining `SELECT` query results using the [UNION](../../sql-reference/statements/select/union-all.md) expression.
Possible values:
- `'DISTINCT'` — ClickHouse outputs rows as a result of combining queries removing duplicate rows.
- `'ALL'` — ClickHouse outputs all rows as a result of combining queries including duplicate rows.
- `''` — Clickhouse generates an exception when used with `UNION`.
Default value: `'DISTINCT'`.
**Example of using the 'DISTINCT' value**
Query:
```sql
SET union_default_mode = 'DISTINCT';
SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 2;
```
Result:
```text
┌─1─┐
│ 1 │
└───┘
┌─1─┐
│ 2 │
└───┘
┌─1─┐
│ 3 │
└───┘
```
**Example of using the 'ALL' value**
Query:
```sql
SET union_default_mode = 'ALL';
SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 2;
```
Result:
```text
┌─1─┐
│ 1 │
└───┘
┌─1─┐
│ 2 │
└───┘
┌─1─┐
│ 2 │
└───┘
┌─1─┐
│ 3 │
└───┘
```
**Example of using the '' value**
Query:
```sql
SET union_default_mode = '';
SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 2;
```
Result:
```text
Query id: 8f3755e8-ef76-4d1a-bdb2-7f6fc8a669ec
Received exception from server (version 20.11.1):
Code: 2005. DB::Exception: Received from localhost:9000. DB::Exception: Expected ALL or DISTINCT in SelectWithUnion query, because setting (union_default_mode) is empty.
```
[Original article](https://clickhouse.tech/docs/en/operations/settings/settings/) <!-- hide -->
......@@ -26,12 +26,15 @@ Type casting is performed for unions. For example, if two queries being combined
Queries that are parts of `UNION ALL` can’t be enclosed in round brackets. [ORDER BY](../../../sql-reference/statements/select/order-by.md) and [LIMIT](../../../sql-reference/statements/select/limit.md) are applied to separate queries, not to the final result. If you need to apply a conversion to the final result, you can put all the queries with `UNION ALL` in a subquery in the [FROM](../../../sql-reference/statements/select/from.md) clause.
# UNION DISTINCT Clause {#union-distinct-clause}
The difference between `UNION ALL` and `UNION DISTINCT` is that `UNION DISTINCT` will do a distinct transform for union result, it is equivalent to `SELECT DISTINCT` from a subquery containing `UNION ALL`.
# UNION Clause {#union-clause}
By default, `UNION` has the same behavior as `UNION DISTINCT`, but you can specify union mode by setting `union_default_mode`, values can be 'ALL', 'DISTINCT' or empty string. However, if you use `UNION` with setting `union_default_mode` to empty string, it will throw an exception.
By default, `UNION` has the same behavior as `UNION DISTINCT`, but you can specify union mode by [union_default_mode](../../../operations/settings/settings.md#union-default-mode) setting, values can be `ALL`, `DISTINCT` or an empty string. However, if you use `UNION` with `union_default_mode` setting to empty string, it will throw an exception.
## Implementation Details {#implementation-details}
Queries that are parts of `UNION/UNION ALL/UNION DISTINCT` can be run simultaneously, and their results can be mixed together.
[Original article](https://clickhouse.tech/docs/en/sql-reference/statements/select/union-all/) <!-- hide -->
......@@ -29,6 +29,12 @@ SELECT CounterID, 2 AS table, sum(Sign) AS c
Поддерживается только `UNION ALL`. Обычный `UNION` (`UNION DISTINCT`) не поддерживается. Если вам это нужно `UNION DISTINCT`, вы можете написать `SELECT DISTINCT` из подзапроса, содержащего `UNION ALL`.
# Секция UNION {#union-clause}
По умолчанию, `UNION` ведет себя так же, как и `UNION DISTINCT`. Но вы можете указать режим объединения с помощью настройки [union_default_mode](../../../operations/settings/settings.md#union-default-mode), значениями которой могут быть `ALL`, `DISTINCT` или пустая строка. Однако, если вы используете `UNION` с настройкой `union_default_mode`, значением которой является пустая строка, то сгенерируется исключение.
## Детали реализации {#implementation-details}
Запросы, которые являются частью `UNION ALL` выполняются параллельно, и их результаты могут быть смешаны вместе.
[Оригинальная статья](https://clickhouse.tech/docs/ru/sql-reference/statements/select/union-all/) <!-- hide -->
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册