mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 11:02:08 +00:00
Update
This commit is contained in:
parent
2a66eab876
commit
cec83bb76a
@ -6,10 +6,12 @@ toc_title: Atomic
|
|||||||
|
|
||||||
# Atomic {#atomic}
|
# Atomic {#atomic}
|
||||||
|
|
||||||
It is an experimental database engine, it supports non-blocking `DROP` and `RENAME TABLE` queries and atomic `EXCHANGE TABLES t1 AND t2` queries.
|
It is supports non-blocking `DROP` and `RENAME TABLE` queries and atomic `EXCHANGE TABLES t1 AND t2` queries. Atomic database engine is used by default.
|
||||||
|
|
||||||
## Creating a Database {#creating-a-database}
|
## Creating a Database {#creating-a-database}
|
||||||
|
|
||||||
CREATE DATABASE test ENGINE = Atomic;
|
```sql
|
||||||
|
CREATE DATABASE test ENGINE = Atomic;
|
||||||
|
```
|
||||||
|
|
||||||
[Original article](https://clickhouse.tech/docs/en/engines/database_engines/atomic/) <!--hide-->
|
[Original article](https://clickhouse.tech/docs/en/engines/database_engines/atomic/) <!--hide-->
|
||||||
|
@ -8,7 +8,7 @@ toc_title: Introduction
|
|||||||
|
|
||||||
Database engines allow you to work with tables.
|
Database engines allow you to work with tables.
|
||||||
|
|
||||||
By default, ClickHouse uses its native database engine, which provides configurable [table engines](../../engines/table-engines/index.md) and an [SQL dialect](../../sql-reference/syntax.md).
|
By default, ClickHouse uses database engine [Atomic](../../engines/database-engines/atomic.md). It is provides configurable [table engines](../../engines/table-engines/index.md) and an [SQL dialect](../../sql-reference/syntax.md).
|
||||||
|
|
||||||
You can also use the following database engines:
|
You can also use the following database engines:
|
||||||
|
|
||||||
@ -18,6 +18,4 @@ You can also use the following database engines:
|
|||||||
|
|
||||||
- [Lazy](../../engines/database-engines/lazy.md)
|
- [Lazy](../../engines/database-engines/lazy.md)
|
||||||
|
|
||||||
- [Atomic](../../engines/database-engines/atomic.md)
|
|
||||||
|
|
||||||
[Original article](https://clickhouse.tech/docs/en/database_engines/) <!--hide-->
|
[Original article](https://clickhouse.tech/docs/en/database_engines/) <!--hide-->
|
||||||
|
@ -14,7 +14,7 @@ By default, tables are created only on the current server. Distributed DDL queri
|
|||||||
### With Explicit Schema {#with-explicit-schema}
|
### With Explicit Schema {#with-explicit-schema}
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
|
CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
|
||||||
(
|
(
|
||||||
name1 [type1] [NULL|NOT NULL] [DEFAULT|MATERIALIZED|ALIAS expr1] [compression_codec] [TTL expr1],
|
name1 [type1] [NULL|NOT NULL] [DEFAULT|MATERIALIZED|ALIAS expr1] [compression_codec] [TTL expr1],
|
||||||
name2 [type2] [NULL|NOT NULL] [DEFAULT|MATERIALIZED|ALIAS expr2] [compression_codec] [TTL expr2],
|
name2 [type2] [NULL|NOT NULL] [DEFAULT|MATERIALIZED|ALIAS expr2] [compression_codec] [TTL expr2],
|
||||||
@ -34,7 +34,7 @@ If necessary, primary key can be specified, with one or more key expressions.
|
|||||||
### With a Schema Similar to Other Table {#with-a-schema-similar-to-other-table}
|
### With a Schema Similar to Other Table {#with-a-schema-similar-to-other-table}
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [db.]table_name AS [db2.]name2 [ENGINE = engine]
|
CREATE TABLE [IF NOT EXISTS] [db.]table_name AS [db2.]name2 [ENGINE = engine]
|
||||||
```
|
```
|
||||||
|
|
||||||
Creates a table with the same structure as another table. You can specify a different engine for the table. If the engine is not specified, the same engine will be used as for the `db2.name2` table.
|
Creates a table with the same structure as another table. You can specify a different engine for the table. If the engine is not specified, the same engine will be used as for the `db2.name2` table.
|
||||||
@ -42,13 +42,13 @@ Creates a table with the same structure as another table. You can specify a diff
|
|||||||
### From a Table Function {#from-a-table-function}
|
### From a Table Function {#from-a-table-function}
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [db.]table_name AS table_function()
|
CREATE TABLE [IF NOT EXISTS] [db.]table_name AS table_function()
|
||||||
```
|
```
|
||||||
|
|
||||||
Creates a table with the structure and data returned by a [table function](../../../sql-reference/table-functions/index.md#table-functions).
|
Creates a table with the structure and data returned by a [table function](../../../sql-reference/table-functions/index.md#table-functions).
|
||||||
|
|
||||||
``` sql
|
``` sql
|
||||||
CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [db.]table_name ENGINE = engine AS SELECT ...
|
CREATE TABLE [IF NOT EXISTS] [db.]table_name ENGINE = engine AS SELECT ...
|
||||||
```
|
```
|
||||||
|
|
||||||
Creates a table with a structure like the result of the `SELECT` query, with the `engine` engine, and fills it with data from SELECT.
|
Creates a table with a structure like the result of the `SELECT` query, with the `engine` engine, and fills it with data from SELECT.
|
||||||
@ -268,21 +268,11 @@ It’s possible to use tables with [ENGINE = Memory](../../../engines/table-engi
|
|||||||
!!!note "Note"
|
!!!note "Note"
|
||||||
This query is supported only for [Atomic](../../../engines/database_engines/atomic.md) database engine.
|
This query is supported only for [Atomic](../../../engines/database_engines/atomic.md) database engine.
|
||||||
|
|
||||||
If you need to reject(delete) some data from a table, you can create a new table and fill it with a `SELECT` statement that doesn't retrieve unwanted data, then rename it to old table name:
|
If you need to delete some data from a table, you can create a new table and fill it with a `SELECT` statement that doesn't retrieve unwanted data, then drop the old table and rename the new one:
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
CREATE TABLE myNewTable AS myOldTable;
|
CREATE TABLE myNewTable AS myOldTable;
|
||||||
```
|
|
||||||
|
|
||||||
Then load data with:
|
|
||||||
|
|
||||||
```sql
|
|
||||||
INSERT INTO myNewTable SELECT * FROM myOldTable WHERE CounterID <12345;
|
INSERT INTO myNewTable SELECT * FROM myOldTable WHERE CounterID <12345;
|
||||||
```
|
|
||||||
|
|
||||||
Drop old table and rename:
|
|
||||||
|
|
||||||
```sql
|
|
||||||
DROP TABLE myOldTable;
|
DROP TABLE myOldTable;
|
||||||
RENAME TABLE myNewTable TO myOldTable;
|
RENAME TABLE myNewTable TO myOldTable;
|
||||||
```
|
```
|
||||||
@ -293,18 +283,18 @@ Instead of above, you can use the following:
|
|||||||
REPLACE TABLE myOldTable SELECT * FROM myOldTable WHERE CounterID <12345;
|
REPLACE TABLE myOldTable SELECT * FROM myOldTable WHERE CounterID <12345;
|
||||||
```
|
```
|
||||||
|
|
||||||
**Examples:**
|
### Syntax
|
||||||
|
|
||||||
`REPLACE` for a non-existent table will cause an error.
|
{CREATE [OR REPLACE]|REPLACE} TABLE [db.]table_name
|
||||||
|
|
||||||
```sql
|
All syntax forms for `CREATE` query also work for this query. `REPLACE` for a non-existent table will cause an error.
|
||||||
CREATE DATABASE base ENGINE = Atomic;
|
|
||||||
REPLACE TABLE base.t1 (n UInt64, s String) ENGINE = MergeTree ORDER BY n; -- { serverError 60 }
|
### Examples:
|
||||||
```
|
|
||||||
|
|
||||||
Using `REPLACE` query to change data in columns.
|
Using `REPLACE` query to change data in columns.
|
||||||
|
|
||||||
```sql
|
```sql
|
||||||
|
CREATE DATABASE base ENGINE = Atomic;
|
||||||
CREATE OR REPLACE TABLE base.t1 (n UInt64, s String) ENGINE = MergeTree ORDER BY n;
|
CREATE OR REPLACE TABLE base.t1 (n UInt64, s String) ENGINE = MergeTree ORDER BY n;
|
||||||
INSERT INTO base.t1 VALUES (1, 'test');
|
INSERT INTO base.t1 VALUES (1, 'test');
|
||||||
SELECT * FROM base.t1;
|
SELECT * FROM base.t1;
|
||||||
|
Loading…
Reference in New Issue
Block a user