Fix PostgreSQL proxy timestamp text output adding trailing .0#38566
Open
daguimu wants to merge 1 commit intoapache:masterfrom
Open
Fix PostgreSQL proxy timestamp text output adding trailing .0#38566daguimu wants to merge 1 commit intoapache:masterfrom
daguimu wants to merge 1 commit intoapache:masterfrom
Conversation
0f0f9c1 to
3f3924a
Compare
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.
Problem
When querying a
TIMESTAMPcolumn without fractional seconds through ShardingSphere-Proxy (PostgreSQL protocol), the result includes a trailing.0(e.g.,1973-06-03 10:30:01.0), whereas native PostgreSQL returns1973-06-03 10:30:01. This formatting mismatch can break clients and tests relying on stable textual output.Root Cause
In
PostgreSQLDataRowPacket#writeTextValue, non-binary column values fall through to the genericeach.toString()branch. When the value is ajava.sql.Timestamp,Timestamp.toString()always emits a fractional part (at minimum.0), which does not match PostgreSQL's text protocol behavior of omitting trailing zero fractional seconds.Fix
java.sql.TimestampinwriteTextValuethat formats the timestamp according to PostgreSQL text output rules:formatTimestampmethod withinPostgreSQLDataRowPacketTests Added
.0timestamp_no_fractional— verifies1973-06-03 10:30:01(exact reproduction from issue)timestamp_with_fractional— verifies2024-01-15 14:30:45.123timestamp_trailing_zeros_stripped— verifies.120becomes.12timestamp_microsecond_precision— verifies2024-01-15 14:30:45.123456Impact
Only affects PostgreSQL text protocol timestamp formatting in the proxy. No changes to binary protocol, other data types, or any other module. Existing behavior for all non-Timestamp types is unchanged.
Fixes #37437