Skip to content

fix(clickhouse): preserve Decimal precision when scale is null (#2192) - #2314

Merged
openai0229 merged 2 commits into
OtterMind:mainfrom
liulipengju:260728-fix-clickhouse-decimal-precision
Jul 28, 2026
Merged

fix(clickhouse): preserve Decimal precision when scale is null (#2192)#2314
openai0229 merged 2 commits into
OtterMind:mainfrom
liulipengju:260728-fix-clickhouse-decimal-precision

Conversation

@liulipengju

Copy link
Copy Markdown
Contributor

Title: fix(clickhouse): preserve Decimal precision when scale is null

Description:

Fixes #2192

The buildDataType method in ClickHouseColumnTypeEnum uses columnSize == null || decimalDigits == null as a guard condition for Decimal types. This causes an early return that drops precision when columnSize is set but decimalDigits is null.

Before
Decimal(10) (precision=10, scale=null) → Decimal (precision dropped, broken DDL)
Decimal(10,5) → Decimal(10,5)
After
Decimal(10) → Decimal(10,0) (preserves precision, uses 0 as default scale)
Decimal(10,5) → Decimal(10,5) (unchanged)
Changes
Changed guard from columnSize == null || decimalDigits == null to columnSize == null only
Fixed the size-only branch to output Decimal(P,0) (ClickHouse requires both P and S)
Removed unreachable dead code in the previous two-branch else if structure

@liulipengju
liulipengju requested a review from openai0229 as a code owner July 28, 2026 05:30
@openai0229 openai0229 moved this to In Review in Chat2DB Community Jul 28, 2026
@openai0229
openai0229 force-pushed the 260728-fix-clickhouse-decimal-precision branch from 98253cc to b0cb0d7 Compare July 28, 2026 12:52
MonkeyCode-AI and others added 2 commits July 28, 2026 21:01
…Mind#2192)

Change the guard condition from (columnSize == null || decimalDigits == null) to
(columnSize == null) only. This prevents an early return that drops precision when
scale is null but precision is set. Also fix the size-only branch to output
Decimal(P,0) instead of Decimal(P) since ClickHouse requires both P and S.
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
@openai0229
openai0229 force-pushed the 260728-fix-clickhouse-decimal-precision branch from b0cb0d7 to c03a49b Compare July 28, 2026 13:02
@openai0229
openai0229 merged commit 6693185 into OtterMind:main Jul 28, 2026
14 of 21 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

ClickHouse buildDataType drops Decimal precision when scale is null (needs Decimal(P,0) not Decimal(P))

3 participants