Skip to content

Commit

Permalink
Merge pull request cockroachdb#84665 from ecwall/backport21.2-84613
Browse files Browse the repository at this point in the history
release-21.2: DatumToHLC truncates timestamp
  • Loading branch information
ecwall authored Jul 19, 2022
2 parents afebfe2 + 415c855 commit 840df39
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/as_of
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ SELECT * FROM (SELECT now()) AS OF SYSTEM TIME '2018-01-01'
----
2018-01-01 00:00:00 +0000 UTC

# Verify that timezones are not truncated

query T
SELECT * FROM (SELECT now()) AS OF SYSTEM TIME '2018-01-01 00:00:00-1:00'
----
2018-01-01 01:00:00 +0000 UTC

# Verify that zero intervals indistinguishable from zero cause an error.

statement error pq: AS OF SYSTEM TIME: interval value '0.1us' too small, absolute value must be >= 1µs
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sem/tree/as_of.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func DatumToHLC(evalCtx *EvalContext, stmtTimestamp time.Time, d Datum) (hlc.Tim
syn = true
}
// Attempt to parse as timestamp.
if dt, _, err := ParseDTimestamp(evalCtx, s, time.Nanosecond); err == nil {
if dt, _, err := ParseDTimestampTZ(evalCtx, s, time.Nanosecond); err == nil {
ts.WallTime = dt.Time.UnixNano()
ts.Synthetic = syn
break
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/timeutil/pgdate/field_extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ func (fe *fieldExtract) MakeTimestamp() time.Time {
return time.Date(year, time.Month(month), day, hour, min, sec, nano, fe.MakeLocation())
}

// MakeTimestampWIthoutTimezone returns a time.Time containing all extracted
// MakeTimestampWithoutTimezone returns a time.Time containing all extracted
// information, minus any timezone information (which is stripped). The returned
// time always has UTC location. See ParseTimestampWithoutTimezone.
func (fe *fieldExtract) MakeTimestampWithoutTimezone() time.Time {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/timeutil/pgdate/parsing.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func ParseTimestamp(
// For example, all these inputs return 2020-06-26 01:02:03 +0000 UTC:
// - '2020-06-26 01:02:03';
// - '2020-06-26 01:02:03+04';
// - 'now', if the local local time (in the current timezone) is
// - 'now', if the local time (in the current timezone) is
// 2020-06-26 01:02:03. Note that this does not represent the same time
// instant, but the one that "reads" the same in UTC.
//
Expand Down

0 comments on commit 840df39

Please sign in to comment.