2020-04-03 13:23:32 +00:00
---
toc_priority: 60
toc_title: clickhouse-local
---
2020-03-20 10:10:48 +00:00
# clickhouse-local {#clickhouse-local}
2018-07-18 10:00:53 +00:00
2018-09-06 17:58:37 +00:00
The `clickhouse-local` program enables you to perform fast processing on local files, without having to deploy and configure the ClickHouse server.
2018-07-18 10:00:53 +00:00
2020-04-30 18:19:18 +00:00
Accepts data that represent tables and queries them using [ClickHouse SQL dialect ](../../sql-reference/index.md ).
2018-07-18 10:00:53 +00:00
2018-09-06 17:58:37 +00:00
`clickhouse-local` uses the same core as ClickHouse server, so it supports most of the features and the same set of formats and table engines.
2018-07-18 10:00:53 +00:00
2018-09-06 17:58:37 +00:00
By default `clickhouse-local` does not have access to data on the same host, but it supports loading server configuration using `--config-file` argument.
2018-07-18 10:00:53 +00:00
2020-03-20 10:10:48 +00:00
!!! warning "Warning"
2018-09-06 17:58:37 +00:00
It is not recommended to load production server configuration into `clickhouse-local` because data can be damaged in case of human error.
2018-07-18 10:00:53 +00:00
2021-01-20 03:32:39 +00:00
For temporary data, a unique temporary data directory is created by default.
2020-07-20 10:03:18 +00:00
2020-03-20 10:10:48 +00:00
## Usage {#usage}
2018-09-06 17:58:37 +00:00
Basic usage:
2020-03-20 10:10:48 +00:00
``` bash
2020-07-22 13:38:47 +00:00
$ clickhouse-local --structure "table_structure" --input-format "format_of_incoming_data" \
--query "query"
2018-07-18 10:00:53 +00:00
```
2018-09-06 17:58:37 +00:00
Arguments:
2020-03-21 04:11:51 +00:00
- `-S` , `--structure` — table structure for input data.
- `-if` , `--input-format` — input format, `TSV` by default.
- `-f` , `--file` — path to data, `stdin` by default.
2021-01-20 03:32:39 +00:00
- `-q` , `--query` — queries to execute with `;` as delimeter. You must specify either `query` or `queries-file` option.
- `-qf` , `--queries-file` - file path with queries to execute. You must specify either `query` or `queries-file` option.
2020-03-21 04:11:51 +00:00
- `-N` , `--table` — table name where to put output data, `table` by default.
- `-of` , `--format` , `--output-format` — output format, `TSV` by default.
2021-01-20 03:32:39 +00:00
- `-d` , `--database` — default database, `_local` by default.
2020-03-21 04:11:51 +00:00
- `--stacktrace` — whether to dump debug output in case of exception.
2021-07-29 15:20:55 +00:00
- `--echo` — print query before execution.
2020-03-21 04:11:51 +00:00
- `--verbose` — more details on query execution.
2021-01-20 03:32:39 +00:00
- `--logger.console` — Log to console.
- `--logger.log` — Log file name.
- `--logger.level` — Log level.
- `--ignore-error` — do not stop processing if a query failed.
- `-c` , `--config-file` — path to configuration file in same format as for ClickHouse server, by default the configuration empty.
- `--no-system-tables` — do not attach system tables.
2020-03-21 04:11:51 +00:00
- `--help` — arguments references for `clickhouse-local` .
2021-01-20 03:32:39 +00:00
- `-V` , `--version` — print version information and exit.
2018-09-06 17:58:37 +00:00
Also there are arguments for each ClickHouse configuration variable which are more commonly used instead of `--config-file` .
2018-07-18 10:00:53 +00:00
2020-07-20 10:03:18 +00:00
2020-03-20 10:10:48 +00:00
## Examples {#examples}
2018-07-18 10:00:53 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2020-07-22 13:38:47 +00:00
$ echo -e "1,2\n3,4" | clickhouse-local --structure "a Int64, b Int64" \
--input-format "CSV" --query "SELECT * FROM table"
2018-07-18 10:00:53 +00:00
Read 2 rows, 32.00 B in 0.000 sec., 5182 rows/sec., 80.97 KiB/sec.
2020-03-20 10:10:48 +00:00
1 2
3 4
2018-07-18 10:00:53 +00:00
```
2018-09-06 17:58:37 +00:00
Previous example is the same as:
2018-07-18 10:00:53 +00:00
2020-03-20 10:10:48 +00:00
``` bash
2020-07-22 13:38:47 +00:00
$ echo -e "1,2\n3,4" | clickhouse-local --query "
CREATE TABLE table (a Int64, b Int64) ENGINE = File(CSV, stdin);
SELECT a, b FROM table;
DROP TABLE table"
2018-07-18 10:00:53 +00:00
Read 2 rows, 32.00 B in 0.000 sec., 4987 rows/sec., 77.93 KiB/sec.
2020-03-20 10:10:48 +00:00
1 2
3 4
2018-07-18 10:00:53 +00:00
```
2020-07-23 07:20:40 +00:00
You don't have to use `stdin` or `--file` argument, and can open any number of files using the [`file` table function ](../../sql-reference/table-functions/file.md ):
2020-07-22 13:38:47 +00:00
``` bash
$ echo 1 | tee 1.tsv
1
$ echo 2 | tee 2.tsv
2
$ clickhouse-local --query "
select * from file('1.tsv', TSV, 'a int') t1
cross join file('2.tsv', TSV, 'b int') t2"
1 2
```
2020-03-20 10:10:48 +00:00
Now let’ s output memory user for each Unix user:
2018-07-18 10:00:53 +00:00
2021-01-25 22:39:23 +00:00
Query:
2020-03-20 10:10:48 +00:00
``` bash
2020-07-22 13:38:47 +00:00
$ ps aux | tail -n +2 | awk '{ printf("%s\t%s\n", $1, $4) }' \
| clickhouse-local --structure "user String, mem Float64" \
--query "SELECT user, round(sum(mem), 2) as memTotal
FROM table GROUP BY user ORDER BY memTotal DESC FORMAT Pretty"
2019-09-23 15:31:46 +00:00
```
2020-03-20 10:10:48 +00:00
2021-01-25 22:39:23 +00:00
Result:
2020-03-20 10:10:48 +00:00
``` text
2018-07-18 10:00:53 +00:00
Read 186 rows, 4.15 KiB in 0.035 sec., 5302 rows/sec., 118.34 KiB/sec.
┏━━━━━━━━━━┳━━━━━━━━━━┓
┃ user ┃ memTotal ┃
┡━━━━━━━━━━╇━━━━━━━━━━┩
│ bayonet │ 113.5 │
├──────────┼──────────┤
│ root │ 8.8 │
├──────────┼──────────┤
...
```
2018-10-16 10:47:17 +00:00
2021-09-19 20:05:54 +00:00
[Original article ](https://clickhouse.com/docs/en/operations/utils/clickhouse-local/ ) <!--hide-->