Skip to content

fix: bind complete named parameters containing dollar signs - #2030

Merged
joe-clickhouse merged 6 commits into
ClickHouse:mainfrom
sankalpsthakur:fix/issue-1955-named-dollar
Nov 21, 2026
Merged

joe-clickhouse merged 6 commits into
ClickHouse:mainfrom
sankalpsthakur:fix/issue-1955-named-dollar

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1955.

Recognize $ inside client-side @name placeholders. This prevents @id$x from selecting id and leaving $x in the query, and restores missing-parameter errors for the complete name.

Adds unit coverage for leading, trailing, repeated and digit-adjacent dollar signs, quotes/comments, missing names and DateNamed; adds real-server tests for native/HTTP and direct/database/sql APIs.

Validation: run 35297161774.

  • New regressions fail against unchanged source and pass after the fix.
  • 11 unit subcases and 20 server cases pass.
  • Full race-enabled test command passes; existing skips are retained.
  • Lint reports zero issues.
  • Both binding fixes also pass their combined unit/integration regressions and lint.

AI tools assisted with implementation, validation and this description.


Note

Low Risk
Small, targeted change to named-placeholder parsing plus tests; no auth or data-path redesign.

Overview
Fixes client-side @name binding when parameter names include $, which ClickHouse allows but the binder previously rejected after the first invalid character (e.g. @id$x bound as @id and left $x in the SQL).

isNameChar now treats $ as part of a named placeholder so the scanner consumes the full name, substitutes values correctly, and still errors when the complete name is missing.

Adds TestBindNamedDollar (edge cases, quotes/comments, DateNamed) and Test1955 integration coverage for native/HTTP and database/sql paths.

Reviewed by Cursor Bugbot for commit cbf4f1c. Bugbot is set up for automated code reviews on this repo. Configure here.

@sankalpsthakur

Copy link
Copy Markdown
Contributor Author

still current with main, ptal

Comment thread tests/issues/issue_1955_test.go Resolved
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Claude review

Adds $ to the characters that bindNamed accepts in a client-side @name placeholder, so @id$x binds the full name id$x and does not bind id and leave $x in the query. The change is correct and small. Verdict: approve.

What I checked:

  • isNameChar has one caller, the @name scanner in bindNamed. The ? and $N scanners and the server-side {name:Type} path do not use it, so they do not change.
  • Native and database/sql calls, on TCP and HTTP, all go through the same bind function. One fix covers all four paths.
  • Quoted text, quoted identifiers and comments stay protected. The unit test proves this.
  • The regression test is in tests/issues/issue_1955_test.go, covers the two protocols and the two API surfaces, registers t.Cleanup for each connection, and does not create a table.

Behavior change to know: @name$suffix with only name bound now returns have no arg for "@name$suffix" param. Before, it bound name and sent $suffix to the server. This is the intended fix. A query that put a heredoc directly after a placeholder with no separator (@id$$text$$) changes too, but that is not practical SQL.

Blind spots:

Verdict: ✅ Approve

Inline comments are attached to the relevant lines. This summary updates in place on re-review.

joe-clickhouse and others added 2 commits November 20, 2026 15:30
Move the unit cases into bind_test.go next to the other named bind
tests and drop the subtests that pass without the fix. Use
TestProtocols and one helper in the issue test, and check the
client error text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@joe-clickhouse
joe-clickhouse requested a review from a team as a code owner November 21, 2026 00:31
@github-actions

Copy link
Copy Markdown
Contributor

AI review gate — Human approval in place of AI review

Approved on the head commit by joe-clickhouse (write access, not the author), standing in for the AI review:

  • Cursor Bugbot is still reviewing this commit.

What to do:

  • Nothing to do yet if the review is running. The gate turns green when it finishes clean.
  • No review showing up? Post bugbot run as a new top-level PR comment. If that does nothing, Bugbot is probably not enabled for this repository: ask a repository administrator.

Evaluated at cbf4f1c6. This required workflow does not re-run on its own once the AI review later concludes — check the Cursor Bugbot check on this commit directly for its current state.

@joe-clickhouse

Copy link
Copy Markdown
Contributor

Thanks! Looks good. The server reads id$x as one word, so the @name scanner should too.

I pushed a small cleanup of the tests. The unit cases now live in bind_test.go next to the other named bind tests, and I dropped two subtests that passed without the fix. The issue test now uses TestProtocols and one helper instead of three copies of the same loop.

@polyglotAI-bot polyglotAI-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve: no blocking problems and no inline comments.

  • The new tests fail with the bind.go of main and pass on this head: 7 unit subtests and 10 server cases, ClickHouse 26.10.4.
  • A differential run of the old and new bindNamed on 300,000 random queries changed the output only where an @name is next to a $.
  • ClickHouse 26.10.4 reads id$x and $x as one name, so the placeholder now ends where the server's name ends.

@security-ai-gate-reviewer security-ai-gate-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co-signing @joe-clickhouse's approval of cbf4f1c: the AI review gate is green on this commit.

@joe-clickhouse
joe-clickhouse merged commit aafefbc into ClickHouse:main Nov 21, 2026
16 checks passed
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.

bind: $ is not a name character in @name placeholders, so $-containing parameter names are unusable and the wrong parameter can be silently substituted

4 participants