Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtins: fix handling of <1 seconds in make_timestamp{tz} #136804

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/datetime
Original file line number Diff line number Diff line change
Expand Up @@ -2064,6 +2064,18 @@ SELECT make_timestamp(2013, 7, 15, 8, 15, 23.5231231244234)::string
make_timestamp
2013-07-15 08:15:23.523123

# Test with seconds < 1.

query T
select make_timestamp(1, 1, 1, 0, 0, 0);
----
0001-01-01 00:00:00 +0000 +0000

query T
select make_timestamp(1, 1, 1, 0, 0, 0.1234);
----
0001-01-01 00:00:00.1234 +0000 +0000

statement error pgcode 22008 pq: make_timestamp\(\): year value of 0 is not valid
SELECT make_timestamp(0, 7, 15, 8, 15, 23.5);

Expand Down Expand Up @@ -2098,6 +2110,18 @@ SELECT make_timestamptz(2013, 7, 15, 8, 15, 23.5, 'America/New_York')
make_timestamptz
2013-07-15 07:15:23.5 -0500 EST

# Test with seconds < 1.

query T
select make_timestamptz(2020, 1, 1, 0, 0, 0, 'America/New_York');
----
2020-01-01 00:00:00 -0500 EST

query T
select make_timestamptz(2020, 1, 1, 0, 0, 0.1234, 'America/New_York');
----
2020-01-01 00:00:00.1234 -0500 EST

statement error pgcode 22008 pq: make_timestamptz\(\): year value of 0 is not valid
SELECT make_timestamptz(0, 7, 15, 8, 15, 23.5);

Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -11998,8 +11998,8 @@ func makeTimestampStatementBuiltinOverload(withOutputTZ bool, withInputTZ bool)
hour := int(tree.MustBeDInt(args[3]))
min := int(tree.MustBeDInt(args[4]))
sec := float64(tree.MustBeDFloat(args[5]))
truncatedSec := math.Floor(sec)
nsec := math.Mod(sec, truncatedSec) * float64(time.Second)
truncatedSec, remainderSec := math.Modf(sec)
nsec := remainderSec * float64(time.Second)
t := time.Date(year, month, day, hour, min, int(truncatedSec), int(nsec), location)
if withOutputTZ {
return tree.MakeDTimestampTZ(t, time.Microsecond)
Expand Down
Loading