Skip to content

[jdbc-v2] Document BigDecimal precision in PreparedStatement queries - #3409

Open
polyglotAI-bot wants to merge 1 commit into
mainfrom
polyglot/jdbc-v2-bigdecimal-precision-docs
Open

polyglotAI-bot wants to merge 1 commit into
mainfrom
polyglot/jdbc-v2-bigdecimal-precision-docs

Conversation

@polyglotAI-bot

@polyglotAI-bot polyglotAI-bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Related to #2762 (docs requested in #2762 (comment)). This PR does not close the issue.

Documents why setBigDecimal() can lose precision in a jdbc-v2 query condition, and how to send the full value. Docs only: the driver keeps the unquoted BigDecimal.toString() literal.

Changes

  • docs/clickhouse-docs/jdbc.mdx: new section "Decimal and Float64 Values in Queries" (#decimal-and-float64-values-in-queries): the cause, the insert paths, Options A, B and C, and the text form of Float64 values. Two links to it from the Numeric Types notes.
  • docs/integration-jdbc.md: Step 5 section "Decimal parameters in queries" with the method snippet, and two Common Pitfalls entries.
  • docs/features.md: a jdbc-v2 compatibility-sensitive trait for the BigDecimal literal rendering.

Verification

ClickHouse 26.10.4, driver built from main. I used scratch programs, which are not part of this PR.

  • setBigDecimal() in WHERE d < ? returns wrong rows for Decimal(18, 4), Decimal(38, 10) and Decimal(76, 20). setObject() with Types.DECIMAL gives the same Float64 literal.
  • Option A (CAST, toDecimal64/128/256 with setString()), Option B and Option C return the correct rows for all three types. With Option A, CAST(...) + 1 stays Decimal(38, 10).
  • Option B: ? + 1, abs(?) and d + ? fail with ILLEGAL_TYPE_OF_ARGUMENT. SELECT ? returns String.
  • getString() on Float64 gives 1.0E-4, 1.0E7 and 1.23456789012345677E18 (JDK 17).
  • The snippet compiles at the Java 8 level and returns the expected rows. jdbc.mdx parses with MDX 3 (with the heading IDs removed). The Mintlify check runs in CI.

Differences from the request

  • Inserts: the default PreparedStatement also keeps the full precision when each ? is a full value in INSERT ... VALUES (one row and batch). VALUES (? + 0) and INSERT ... SELECT ? lose precision with both insert paths. The docs say this.
  • jdbc_type_mappings takes a class name. The docs use Float64=java.lang.String (Float64=String also works).
  • The docs give no digit count for Double.toString(), because JDK 17 gives 18 significant digits for some values.
  • toDecimal128(?, S) with setBigDecimal() loses precision. The docs say to use these functions only with setString(). (CAST(? AS Decimal(P, S)) with setBigDecimal() returned the correct rows, because the server casts the literal text. The docs still recommend setString(), as the request says.)
  • A BigDecimal integer that is too large for 64 bits is also read as Float64. The docs say this.

Compatibility

No change to code, behavior, public API or defaults. docs/changes_checklist.md: no section applies. No CHANGELOG fragment, because this PR changes only docs.

Checklist

  • For significant changes, documentation was updated (the docs/clickhouse-docs pages in this repo sync to clickhouse-docs)

🤖 Generated with Claude Code


Note

Low Risk
Documentation-only; no code, API, or runtime behavior changes.

Overview
Documentation-only PR — no driver code or behavior changes.

Adds cross-linked guidance for jdbc-v2 PreparedStatement BigDecimal precision: unquoted literals from setBigDecimal() / setObject(BigDecimal) (via BigDecimal.toString()) can be parsed as Float64, which breaks comparisons on high-precision Decimal columns but not plain INSERT ... VALUES (?) placeholders.

jdbc.mdx: New section Decimal and Float64 Values in Queries (workarounds A–C, insert exceptions, Float64 text via getString()); numeric-type notes link to it.

integration-jdbc.md: Matching Decimal parameters in queries section with sample code; Common Pitfalls entries for setBigDecimal() in WHERE and getString() on Float64.

features.md: Documents this as a jdbc-v2 compatibility-sensitive trait.

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

jdbc-v2 renders a BigDecimal parameter as an unquoted literal
(BigDecimal.toString()). ClickHouse reads it as Float64, so a condition
such as WHERE col_decimal < ? can give wrong results for high-precision
Decimal columns. The driver keeps this rendering (maintainer decision on
the issue).

Document the cause, which inserts are not affected, and three ways to
send the full value: CAST(? AS Decimal(P, S)) with setString(), a string
in a direct comparison, and typed client-v2 query parameters. Also
document the text form of Float64 values. Record the rendering as a
jdbc-v2 compatibility-sensitive trait in docs/features.md.

Refs: #2762

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@polyglotAI-bot
polyglotAI-bot requested review from a team and mzitnik as code owners November 24, 2026 00:54

@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.

Auto-approved by the AI review gate on 4a8b36c. Details in the approver's comment on this pull request.

@security-ai-gate-reviewer

Copy link
Copy Markdown

AI review gate — auto-approved

4a8b36cb929e is approved by security-ai-gate-reviewer[bot], an automated identity, not a human. The approval stands on the required AI review: Cursor Bugbot concluded green on this commit and the AI review gate is SUCCESS (its own comment has the verdict), and the change touches no path that requires a human reviewer. It is bound to this commit: a new push dismisses it and the approver re-evaluates.

History (latest 5 heads, newest first)

  • 4a8b36cb929e approved — green: Cursor Bugbot

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.

1 participant