Skip to content

Write to Merge storage #683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: antalya
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions docs/en/engines/table-engines/special/merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Reading is automatically parallelized. Writing to a table is not supported. When
## Creating a Table {#creating-a-table}

``` sql
CREATE TABLE ... Engine=Merge(db_name, tables_regexp)
CREATE TABLE ... Engine=Merge(db_name, tables_regexp [, table_to_write])
```

## Engine Parameters
Expand All @@ -32,6 +32,14 @@ CREATE TABLE ... Engine=Merge(db_name, tables_regexp)
Regular expressions — [re2](https://github.com/google/re2) (supports a subset of PCRE), case-sensitive.
See the notes about escaping symbols in regular expressions in the "match" section.

### table_to_write {#table_to_write}

`table_to_write` - Table name to write during inserts into `Merge` table.
Possible values:
- `'db_name.table_name'` - insert into the specific table in the specific database.
- `'table_name'` - insert into table `db_name.table_name`. Allowed only when the first parameter `db_name` is not a regular expression.
- `auto` - insert into the last table passed to `tables_regexp` in lexicographical order. Allowed only when the first parameter `db_name` is not a regular expression.

## Usage {#usage}

When selecting tables to read, the `Merge` table itself is not selected, even if it matches the regex. This is to avoid loops.
Expand Down Expand Up @@ -62,7 +70,7 @@ CREATE TABLE WatchLog_new(date Date, UserId Int64, EventType String, Cnt UInt64)
ENGINE=MergeTree PARTITION BY date ORDER BY (UserId, EventType) SETTINGS index_granularity=8192;
INSERT INTO WatchLog_new VALUES ('2018-01-02', 2, 'hit', 3);

CREATE TABLE WatchLog as WatchLog_old ENGINE=Merge(currentDatabase(), '^WatchLog');
CREATE TABLE WatchLog as WatchLog_old ENGINE=Merge(currentDatabase(), '^WatchLog', 'WatchLog_new');

SELECT * FROM WatchLog;
```
Expand All @@ -76,6 +84,22 @@ SELECT * FROM WatchLog;
└────────────┴────────┴───────────┴─────┘
```

Insert to table `WatchLog` is going into table `WatchLog_new`
```sql
INSERT INTO WatchLog VALUES ('2018-01-03', 3, 'hit', 3);

SELECT * FROM WatchLog_New;
```

```text
┌───────date─┬─UserId─┬─EventType─┬─Cnt─┐
│ 2018-01-02 │ 2 │ hit │ 3 │
└────────────┴────────┴───────────┴─────┘
┌───────date─┬─UserId─┬─EventType─┬─Cnt─┐
│ 2018-01-03 │ 3 │ hit │ 3 │
└────────────┴────────┴───────────┴─────┘
```

## Virtual Columns {#virtual-columns}

- `_table` — Contains the name of the table from which data was read. Type: [String](../../../sql-reference/data-types/string.md).
Expand Down
Loading
Loading