fix(bind): treat []byte as String and time.Duration as Time - #1945
Open
sankalpsthakur wants to merge 2 commits into
Open
fix(bind): treat []byte as String and time.Duration as Time#1945sankalpsthakur wants to merge 2 commits into
sankalpsthakur wants to merge 2 commits into
Conversation
Client-side formatValue had no cases for []byte or time.Duration, so []byte fell through to reflect.Slice (Array(UInt8)) and Duration hit fmt.Stringer (Go's "14h30m0s"). Both are unusable against String and Time/Time64 columns respectively. - Quote []byte like string (escape \, ', and NUL as \0) - Format time.Duration / *time.Duration as HH:MM:SS[.frac] - Unit tests for bind + formatDuration Fixes ClickHouse#1942 AI assistance: used for locating formatValue fallthrough and drafting the bind tests; change reviewed and verified with go test.
chernser
reviewed
Aug 5, 2026
| } | ||
| fracStr := fmt.Sprintf("%09d", frac.Nanoseconds()) | ||
| fracStr = strings.TrimRight(fracStr, "0") | ||
| return fmt.Sprintf("%s%02d:%02d:%02d.%s", sign, hours, mins, secs, fracStr) |
There was a problem hiding this comment.
add single quotes as formatTime puts them - API should be consistent.
Contributor
Author
There was a problem hiding this comment.
Addressed in 8393cdc, please take another look.
chernser
reviewed
Aug 5, 2026
| return formatTime(tz, scale, *v) | ||
| case time.Duration: | ||
| // Must precede fmt.Stringer: Duration.String() is Go's "14h30m0s". | ||
| return quote(formatDuration(v)), nil |
There was a problem hiding this comment.
formatDuration should return quoted string like formatTime does
Contributor
Author
There was a problem hiding this comment.
Addressed in 8393cdc, please take another look.
chernser
reviewed
Aug 5, 2026
|
|
||
| // TestBindDuration checks that time.Duration (the ScanType for ClickHouse | ||
| // Time/Time64) binds as a Time-parseable literal, not Go's duration string. | ||
| func TestBindDuration(t *testing.T) { |
There was a problem hiding this comment.
add tests with Time64 with different precision.
Contributor
Author
There was a problem hiding this comment.
Addressed in 8393cdc, please take another look.
chernser
requested changes
Aug 5, 2026
…recision tests Address review feedback from chernser: - formatDuration now returns quoted string like formatTime, including single quotes in the return value for API consistency. - Add TestBindDuration_Time64Precision covering Time/Time64 with different precisions (seconds, milli, micro, nano) and composite types. Fixes ClickHouse#1942 Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>
Contributor
Author
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
Fixes client-side parameter binding for two Go types that previously fell through to unusable SQL literals in
formatValue(bind.go):[]byte— was rendered viareflect.SliceasArray(UInt8)([65, 0, 66]). Now quoted as a ClickHouseStringliteral with the same escaping asstring(\,', and NUL as\0).time.Duration/*time.Duration— matchedfmt.Stringerand produced Go’s duration form ('14h30m0s'). Now rendered as a Time/Time64-parseableHH:MM:SS[.frac]literal.time.Durationis the driver’s ownScanTypeforTime/Time64.Fixes #1942
Checklist
Tests
AI disclosure
AI assistance was used to locate the
formatValuefallthrough and draft the unit tests. The change was reviewed, kept minimal to the bind path, and verified with the package unit tests above.AI/LLM disclosure