clickhouse-client --multiquery: Run a SQL Script
clickhouse-client --multiquery executes multiple semicolon-separated statements in one invocation, which is how you apply a ClickHouse migration file.
Without --multiquery the client runs only the first statement. For a schema file with many statements, --multiquery (or --multiquery via stdin) is required.
What it does
By default clickhouse-client treats the input as a single query. --multiquery lets it parse and run several statements separated by semicolons, stopping at the first error. Combined with stdin redirection it runs an entire .sql migration file.
Common usage
clickhouse-client --multiquery < migrations/001_init.sql
# inline several statements
clickhouse-client --multiquery --query "CREATE DATABASE IF NOT EXISTS app; \
CREATE TABLE app.t (id UInt64) ENGINE = Memory;"Options
| Flag | What it does |
|---|---|
| --multiquery / -n | Allow multiple semicolon-separated statements |
| < file.sql | Read the script from stdin |
| --query <sql> | Provide the statements inline |
| --database <db> | Default database for the statements |
| --host / --port | Native server endpoint (default 9000) |
In CI
Pipe the migration file into the client with --multiquery so the whole schema applies in one step. Execution stops at the first failed statement and the client exits non-zero, which fails the job; use IF NOT EXISTS so reruns are safe. Recent clickhouse-client versions accept multiple statements by default, but passing --multiquery keeps the behaviour explicit across versions.
Common errors in CI
"Code: 62. DB::Exception: Syntax error: failed at position ..." identifies the offending statement and column. "Multi-statements are not allowed" on an older or differently-built client means you must add --multiquery. A partially applied schema after a mid-file error is normal: fix the statement and rerun with IF NOT EXISTS guards.