Repository navigation
Description
Description
Client.insert(String tableName, List<String> columnNames, ...) builds the INSERT INTO ... (cols) FORMAT ... statement by concatenating the caller-supplied column names verbatim, with no identifier quoting. Column names that require quoting in ClickHouse SQL (spaces, punctuation, etc.) produce an unparsable statement and the server rejects the insert with Code: 62 ... SYNTAX_ERROR.
client-v2/src/main/java/com/clickhouse/client/api/Client.java:1846-1857:
StringBuilder sqlStmt = new StringBuilder("INSERT INTO ").append(tableName);
if (columnNames != null && !columnNames.isEmpty()) {
sqlStmt.append(" (");
for (String columnName : columnNames) {
sqlStmt.append(columnName).append(", ");
}
sqlStmt.deleteCharAt(sqlStmt.length() - 2);
sqlStmt.append(")");
}
sqlStmt.append(" FORMAT ").append(format.name());This affects all insert(...) overloads that take a List<String> columnNames (the InputStream overloads at Client.java:1720/1735 and the DataStreamWriter overloads at Client.java:1793/1810, which all funnel into the method above).
Inserts that do not pass columnNames are unaffected.
ClickHouse server version
26.11.2.4 (official build) — verified against a running server.
Reproduction
TestNG test (run in client-v2, pointed at a local server):
Client client = new Client.Builder()
.addEndpoint("http://localhost:8123")
.setUsername("default").setPassword("")
.compressClientRequest(false)
.build();
final String table = "scratch_quoting_table";
client.execute("DROP TABLE IF EXISTS " + table, new CommandSettings()).get(10, TimeUnit.SECONDS);
client.execute("CREATE TABLE " + table + " (`test id` UInt64, name String) ENGINE = Memory",
new CommandSettings()).get(10, TimeUnit.SECONDS);
List<String> columnNames = Arrays.asList("test id", "name");
byte[] data = "1\tone\n".getBytes(StandardCharsets.UTF_8);
InsertResponse response = client.insert(table, columnNames, new ByteArrayInputStream(data),
ClickHouseFormat.TSV, new InsertSettings()).get(30, TimeUnit.SECONDS);Expected: the row is inserted (writtenRows == 1).
Actual: the statement sent is INSERT INTO scratch_quoting_table (test id, name) FORMAT TSV, and the call fails:
com.clickhouse.client.api.ServerException: Code: 62. DB::Exception: Syntax error: failed at position 41 (id)
(line 1, col 41): id, name ) FORMAT TSV 1 one . Expected one of: token sequence, Dot, token, Comma,
ClosingRoundBracket, end of query. (SYNTAX_ERROR) (version 26.11.2.4 (official build))
Workaround today: pre-quote the names, e.g. Arrays.asList("`test id`", "name").
Suggested fix
In Client.java:1846-1857, wrap each column name in backticks and double any embedded backtick before joining, e.g. "`" + name.replace("`", "") + "`" ``.
Note on compatibility: existing callers may already be pre-quoting as a workaround (the module's own InsertTests pre-quotes table names in a data provider), so the fix should either detect and pass through already-backticked input, or ship as a documented behavior change.
Link
Relayed from https://github.com/ClickHouse/clickhouse-js/issues/1210
Activity
polyglotAI-bot commentedon Nov 26, 2026
Recommendation: Keep open — fix needed
The fix needs one decision: whether names that a caller already quotes (the workaround of the issue) stay accepted.
main: Reproduced on main — onmain(8480ca0) with ClickHouse 26.11.2.4, the issue's steps give the error that it shows; with the pre-quoted names of its workaround, the row is inserted. v0.11.2 and v0.11.1 give the same results.Analysis: Confirmed:
Client.insertappends each column name to the statement as given, with no quoting (client-v2/src/main/java/com/clickhouse/client/api/Client.java:1850). Allinsertoverloads withcolumnNamesreach this code.Automated triage by Polyglot AI. A maintainer makes the final decision.