pgtype: parse extended-range text timestamps - #2631
Closed
sueun-dev wants to merge 1 commit into
Closed
Conversation
Owner
|
Thanks for the report. After a bit more investigation, I determined that the root problem is that the |
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.
PostgreSQL accepts
timestampandtimestamptzvalues outside the range that pgx's current text scan path can parse directly with Go's2006year layout. The binary path already handles values at the high end of PostgreSQL's range, but text/simple-protocol values such as10000-01-02 03:04:05.123456fail before they can scan.This keeps the existing
time.Parseresult for ordinary four-digit AD years. For extended years and BC text values, it normalizes the year to a leap/non-leap surrogate before parsing the date/time and zone fields, then restores the PostgreSQL year into Go's astronomical year numbering. The result is checked against PostgreSQL's timestamp bounds. The extended/BCtimestamptztext path allows the one-year display spillover that a numeric offset can produce, preserves that numeric offset as a fixed offset, and checks the final instant after applying the offset.Checked:
go test ./pgtype -run 'TestTimestampCodecDecodeTextBigTime|TestTimestamptzCodecDecodeTextBigTime|TestTimestamptzCodecDecodeTextBigTimePreservesOffset|TestTimestampCodecDecodeTextInvalid|TestTimestamptzDecodeTextInvalid' -count=1 -vfailed on the text paths (cannot parse "0-01-02 ..." as "-") and on invalid BC/range/offset cases that returned no error.10000-01-02 03:04:05.123456, normalized00000000000010000-01-02 03:04:05.123456, accepted the lower timestamp boundary4714-11-24 00:00:00 BC, rejected4714-11-23 23:59:59.999999 BC, accepted4713-02-29 00:00:00 BC, rejected4712-02-29 00:00:00 BC, rejected294277-01-01 00:00:00, rejected+16time zone displacement, rejected294276-12-31 23:59:59.999999-14, and accepted294276-12-31 23:59:59.999999+14.timestamptzvalues such as294277-01-01 00:00:00+14,294277-01-01 15:58:59.999999+15:59, and4714-11-23 10:00:00-14 BC; it rejected the adjacent out-of-range values294277-01-01 15:59:00+15:59,4714-11-23 09:59:59.999999-14 BC, and4714-11-24 00:00:00+14 BC.go test ./pgtype -run 'TestTimestampCodecDecodeTextBigTime|TestTimestamptzCodecDecodeTextBigTime|TestTimestamptzCodecDecodeTextBigTimePreservesOffset|TestTimestampCodecDecodeTextInvalid|TestTimestamptzDecodeTextInvalid' -count=1 -vgo test -race ./pgtype -run 'TestTimestampCodecDecodeTextBigTime|TestTimestamptzCodecDecodeTextBigTime|TestTimestamptzCodecDecodeTextBigTimePreservesOffset|TestTimestampCodecDecodeTextInvalid|TestTimestamptzDecodeTextInvalid' -count=3PGX_TEST_DATABASE=... go test ./pgtype -count=1TZ=UTC PGX_TEST_DATABASE=... go test ./... -count=1go test ./... -run '^$' -count=1go build ./...git diff --checkgo vet ./pgtypestill reports pre-existing unkeyedpgxtest.ValueRoundTripTestliterals inpgtype/int_test.go; the same vet output reproduces on cleanorigin/master.