Repository navigation
[jdbc-v2] Document BigDecimal precision in PreparedStatement queries - #3409
Open
polyglotAI-bot wants to merge 1 commit into
Open
polyglotAI-bot wants to merge 1 commit into
polyglotAI-bot wants to merge 1 commit into
Conversation
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>
There was a problem hiding this comment.
Auto-approved by the AI review gate on 4a8b36c. Details in the approver's comment on this pull request.
AI review gate — auto-approved
History (latest 5 heads, newest first)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 unquotedBigDecimal.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 ofFloat64values. 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 theBigDecimalliteral rendering.Verification
ClickHouse 26.10.4, driver built from
main. I used scratch programs, which are not part of this PR.setBigDecimal()inWHERE d < ?returns wrong rows forDecimal(18, 4),Decimal(38, 10)andDecimal(76, 20).setObject()withTypes.DECIMALgives the sameFloat64literal.CAST,toDecimal64/128/256withsetString()), Option B and Option C return the correct rows for all three types. With Option A,CAST(...) + 1staysDecimal(38, 10).? + 1,abs(?)andd + ?fail withILLEGAL_TYPE_OF_ARGUMENT.SELECT ?returnsString.getString()onFloat64gives1.0E-4,1.0E7and1.23456789012345677E18(JDK 17).jdbc.mdxparses with MDX 3 (with the heading IDs removed). The Mintlify check runs in CI.Differences from the request
PreparedStatementalso keeps the full precision when each?is a full value inINSERT ... VALUES(one row and batch).VALUES (? + 0)andINSERT ... SELECT ?lose precision with both insert paths. The docs say this.jdbc_type_mappingstakes a class name. The docs useFloat64=java.lang.String(Float64=Stringalso works).Double.toString(), because JDK 17 gives 18 significant digits for some values.toDecimal128(?, S)withsetBigDecimal()loses precision. The docs say to use these functions only withsetString(). (CAST(? AS Decimal(P, S))withsetBigDecimal()returned the correct rows, because the server casts the literal text. The docs still recommendsetString(), as the request says.)BigDecimalinteger that is too large for 64 bits is also read asFloat64. 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
docs/clickhouse-docspages 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
PreparedStatementBigDecimalprecision: unquoted literals fromsetBigDecimal()/setObject(BigDecimal)(viaBigDecimal.toString()) can be parsed asFloat64, which breaks comparisons on high-precisionDecimalcolumns but not plainINSERT ... VALUES (?)placeholders.jdbc.mdx: New section Decimal and Float64 Values in Queries (workarounds A–C, insert exceptions,Float64text viagetString()); numeric-type notes link to it.integration-jdbc.md: Matching Decimal parameters in queries section with sample code; Common Pitfalls entries forsetBigDecimal()inWHEREandgetString()onFloat64.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.