Skip to content

fix(client): quote table names in Insert queries - #573

Closed
Tyagiquamar wants to merge 1 commit into
ClickHouse:masterfrom
Tyagiquamar:fix-insert-table-name-quoting-560
Closed

Tyagiquamar wants to merge 1 commit into
ClickHouse:masterfrom
Tyagiquamar:fix-insert-table-name-quoting-560

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Summary

  • Quote bare and qualified table identifiers in Client::Insert() via new TableNameToQueryString() helper
  • Pass through already backtick-quoted names and quote each part of database.table separately
  • Add integration test for inserting into a hyphenated table name without manual quoting

Fixes #560

Test plan

  • Docker clean build (ubuntu:24.04, clang-18, cmake -DBUILD_TESTS=ON, make -j1) — exit 0
  • Client/ClientCase.InsertQuotesBareTableName/* (2 cases, ClickHouse server on :9000) — PASSED

Client::Insert() now quotes bare and qualified table identifiers so
hyphenated or reserved names work without manual backticks.

Fixes ClickHouse#560
@slabko

slabko commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Thanks for looking at #560, but I'm going to close this PR. Two of the problems are blocking and together they indicate the change wasn't tested or reviewed before submission.

1. It breaks an existing test in the same file you edited.
ut/client_ut.cpp – ClientCase.ColEscapeNameTest passes a double-quoted identifier to Insert():

client_->Insert(R"sql("test_clickhouse_cpp_col_escape_""name_test")sql", block);

TableNameToQueryString only recognises names wrapped in backticks, so this becomes `"test_clickhouse_cpp_col_escape_""name_test"` and the double quotes become part of the identifier. Against a 26.9 server:

Code: 60. DB::Exception: Unknown table expression identifier
'"test_clickhouse_cpp_col_escape_""name_test"' (UNKNOWN_TABLE)

Running clickhouse-cpp-ut --gtest_filter='*ColEscapeNameTest*' against any local server would have shown this immediately. CI on this PR is also already failing on every Linux/macOS build and on all five clickhouse-server integration jobs.

2. It is a silent breaking change to a public API.
Client::Insert(table_name, ...) has always accepted whatever is valid after INSERT INTO. After this change anyone passing "double-quoted" names, partially quoted names (`db`.table, db.`my.table`), or a table function gets mangled SQL with no error from the client. For example `db`.t now becomes ```db```.`t` → Database '\db`' does not exist. A change of this kind needs an explicit compatibility discussion, migration notes, and tests for every behaviour the new doc comment promises – none of which are here. The one added test also creates a non-temporary table that leaks if Insert` throws, unlike every other test in the file.

Please also read AI_POLICY.md in this repository, in particular:

When sending generated code, you take the responsibility in the same way as for the code you have manually typed. Take efforts to read and review the code before sending - otherwise it is disrespectful to maintainers. Take efforts to understand the code base, with or without the help of AI. Low-effort pull requests that require high effort from maintainers will be closed.

We're happy to take AI-assisted contributions, but the author is expected to have read the diff, understood how the touched code is used elsewhere in the repo, and run the test suite. This PR doesn't meet that bar, so I'm closing it. If you'd like to pick #560 up again, please open a new PR that (a) passes the full ut suite against a live server, (b) handles pre-quoted identifiers without breaking them or raises a clear ValidationError, and (c) covers the documented cases (db.table, backtick/double-quote passthrough, escaping) with tests.

@slabko slabko closed this Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client::Insert concatenates the raw table name into SQL — table names needing backquotes cannot be used

2 participants