2019-07-10 07:04:11 +00:00
# File {#table_engines-file}
2018-07-18 10:00:53 +00:00
2019-07-10 07:04:11 +00:00
The File table engine keeps the data in a file in one of the supported [file
formats](../../interfaces/formats.md#formats) (TabSeparated, Native, etc.).
2018-07-18 10:00:53 +00:00
Usage examples:
2018-09-06 17:54:19 +00:00
- Data export from ClickHouse to file.
- Convert data from one format to another.
- Updating data in ClickHouse via editing a file on a disk.
2018-07-18 10:00:53 +00:00
2018-09-06 17:54:19 +00:00
## Usage in ClickHouse Server
2018-07-18 10:00:53 +00:00
```
File(Format)
```
2019-07-10 07:04:11 +00:00
The `Format` parameter specifies one of the available file formats. To perform
`SELECT` queries, the format must be supported for input, and to perform
`INSERT` queries -- for output. The available formats are listed in the
[Formats ](../../interfaces/formats.md#formats ) section.
2018-07-18 10:00:53 +00:00
2018-12-12 17:28:00 +00:00
ClickHouse does not allow to specify filesystem path for`File`. It will use folder defined by [path ](../server_settings/settings.md ) setting in server configuration.
2018-07-18 10:00:53 +00:00
2018-09-06 17:54:19 +00:00
When creating table using `File(Format)` it creates empty subdirectory in that folder. When data is written to that table, it's put into `data.Format` file in that subdirectory.
2018-07-18 10:00:53 +00:00
2018-12-12 17:28:00 +00:00
You may manually create this subfolder and file in server filesystem and then [ATTACH ](../../query_language/misc.md ) it to table information with matching name, so you can query data from that file.
2018-07-18 10:00:53 +00:00
2018-09-06 17:54:19 +00:00
!!! warning
2019-09-03 14:23:51 +00:00
Be careful with this functionality, because ClickHouse does not keep track of external changes to such files. The result of simultaneous writes via ClickHouse and outside of ClickHouse is undefined.
2018-07-18 10:00:53 +00:00
**Example:**
2018-09-06 17:54:19 +00:00
**1.** Set up the `file_engine_table` table:
2018-07-18 10:00:53 +00:00
2018-10-16 10:47:17 +00:00
``` sql
2018-07-18 10:00:53 +00:00
CREATE TABLE file_engine_table (name String, value UInt32) ENGINE=File(TabSeparated)
```
2018-09-06 17:54:19 +00:00
By default ClickHouse will create folder `/var/lib/clickhouse/data/default/file_engine_table` .
2018-07-18 10:00:53 +00:00
2018-09-06 17:54:19 +00:00
**2.** Manually create `/var/lib/clickhouse/data/default/file_engine_table/data.TabSeparated` containing:
2018-07-18 10:00:53 +00:00
```bash
2018-09-06 17:54:19 +00:00
$ cat data.TabSeparated
2018-07-18 10:00:53 +00:00
one 1
two 2
```
2018-09-06 17:54:19 +00:00
**3.** Query the data:
2018-07-18 10:00:53 +00:00
2018-10-16 10:47:17 +00:00
``` sql
2018-07-18 10:00:53 +00:00
SELECT * FROM file_engine_table
```
2018-10-16 10:47:17 +00:00
```
2018-07-18 10:00:53 +00:00
┌─name─┬─value─┐
│ one │ 1 │
│ two │ 2 │
└──────┴───────┘
```
2018-09-06 17:54:19 +00:00
## Usage in Clickhouse-local
2018-07-18 10:00:53 +00:00
2018-12-12 17:28:00 +00:00
In [clickhouse-local ](../utils/clickhouse-local.md ) File engine accepts file path in addition to `Format` . Default input/output streams can be specified using numeric or human-readable names like `0` or `stdin` , `1` or `stdout` .
2018-07-18 10:00:53 +00:00
**Example:**
```bash
$ echo -e "1,2\n3,4" | clickhouse-local -q "CREATE TABLE table (a Int64, b Int64) ENGINE = File(CSV, stdin); SELECT a, b FROM table; DROP TABLE table"
```
2018-08-10 14:44:49 +00:00
## Details of Implementation
2018-07-18 10:00:53 +00:00
2019-07-18 11:04:45 +00:00
- Multiple `SELECT` queries can be performed concurrently, but `INSERT` queries will wait each other.
2018-07-18 10:00:53 +00:00
- Not supported:
2019-09-03 14:23:51 +00:00
- `ALTER`
- `SELECT ... SAMPLE`
- Indices
- Replication
2018-10-16 10:47:17 +00:00
[Original article ](https://clickhouse.yandex/docs/en/operations/table_engines/file/ ) <!--hide-->