Explicitly specifying timezone when casting

to avoid different results on different machines due to default timezone being used in result datatype.
This commit is contained in:
Vasily Nemkov 2020-03-10 16:10:07 +08:00
parent b55cca6286
commit 5fc89bce7c
2 changed files with 25 additions and 25 deletions

View File

@ -68,13 +68,13 @@ subtractHours(N, 1)
subtractMinutes(N, 1) subtractMinutes(N, 1)
subtractSeconds(N, 1) subtractSeconds(N, 1)
subtractQuarters(N, 1) subtractQuarters(N, 1)
CAST(N as DateTime) CAST(N as DateTime('Europe/Minsk'))
CAST(N as Date) CAST(N as Date)
CAST(N as UInt64) CAST(N as UInt64)
CAST(N as DateTime64(0)) CAST(N as DateTime64(0, 'Europe/Minsk'))
CAST(N as DateTime64(3)) CAST(N as DateTime64(3, 'Europe/Minsk'))
CAST(N as DateTime64(6)) CAST(N as DateTime64(6, 'Europe/Minsk'))
CAST(N as DateTime64(9)) CAST(N as DateTime64(9, 'Europe/Minsk'))
# Casting our test values to DateTime(12) will cause an overflow and hence will fail the test under UB sanitizer. # Casting our test values to DateTime(12) will cause an overflow and hence will fail the test under UB sanitizer.
# CAST(N as DateTime64(12)) # CAST(N as DateTime64(12))
# DateTime64(18) will always fail due to zero precision, but it is Ok to test here: # DateTime64(18) will always fail due to zero precision, but it is Ok to test here:

View File

@ -310,10 +310,10 @@ SELECT subtractQuarters(N, 1)
"DateTime('Europe/Minsk')","2019-06-16 19:20:11" "DateTime('Europe/Minsk')","2019-06-16 19:20:11"
"DateTime64(3, 'Europe/Minsk')","2019-06-16 19:20:11.234" "DateTime64(3, 'Europe/Minsk')","2019-06-16 19:20:11.234"
------------------------------------------ ------------------------------------------
SELECT CAST(N as DateTime) SELECT CAST(N as DateTime(\'Europe/Minsk\'))
"DateTime","2019-09-16 00:00:00" "DateTime('Europe/Minsk')","2019-09-15 19:00:00"
"DateTime","2019-09-16 19:20:11" "DateTime('Europe/Minsk')","2019-09-16 19:20:11"
"DateTime","2019-09-16 19:20:11" "DateTime('Europe/Minsk')","2019-09-16 19:20:11"
------------------------------------------ ------------------------------------------
SELECT CAST(N as Date) SELECT CAST(N as Date)
"Date","2019-09-16" "Date","2019-09-16"
@ -325,25 +325,25 @@ SELECT CAST(N as UInt64)
"UInt64",1568650811 "UInt64",1568650811
"UInt64",1568650811 "UInt64",1568650811
------------------------------------------ ------------------------------------------
SELECT CAST(N as DateTime64(0)) SELECT CAST(N as DateTime64(0, \'Europe/Minsk\'))
"DateTime64(0)","2019-09-16 00:00:00" "DateTime64(0, 'Europe/Minsk')","2019-09-15 19:00:00"
"DateTime64(0)","2019-09-16 19:20:11" "DateTime64(0, 'Europe/Minsk')","2019-09-16 19:20:11"
"DateTime64(0)","2019-09-16 19:20:11" "DateTime64(0, 'Europe/Minsk')","2019-09-16 19:20:11"
------------------------------------------ ------------------------------------------
SELECT CAST(N as DateTime64(3)) SELECT CAST(N as DateTime64(3, \'Europe/Minsk\'))
"DateTime64(3)","2019-09-16 00:00:00.000" "DateTime64(3, 'Europe/Minsk')","2019-09-15 19:00:00.000"
"DateTime64(3)","2019-09-16 19:20:11.000" "DateTime64(3, 'Europe/Minsk')","2019-09-16 19:20:11.000"
"DateTime64(3)","2019-09-16 19:20:11.234" "DateTime64(3, 'Europe/Minsk')","2019-09-16 19:20:11.234"
------------------------------------------ ------------------------------------------
SELECT CAST(N as DateTime64(6)) SELECT CAST(N as DateTime64(6, \'Europe/Minsk\'))
"DateTime64(6)","2019-09-16 00:00:00.000000" "DateTime64(6, 'Europe/Minsk')","2019-09-15 19:00:00.000000"
"DateTime64(6)","2019-09-16 19:20:11.000000" "DateTime64(6, 'Europe/Minsk')","2019-09-16 19:20:11.000000"
"DateTime64(6)","2019-09-16 19:20:11.234000" "DateTime64(6, 'Europe/Minsk')","2019-09-16 19:20:11.234000"
------------------------------------------ ------------------------------------------
SELECT CAST(N as DateTime64(9)) SELECT CAST(N as DateTime64(9, \'Europe/Minsk\'))
"DateTime64(9)","2019-09-16 00:00:00.000000000" "DateTime64(9, 'Europe/Minsk')","2019-09-15 19:00:00.000000000"
"DateTime64(9)","2019-09-16 19:20:11.000000000" "DateTime64(9, 'Europe/Minsk')","2019-09-16 19:20:11.000000000"
"DateTime64(9)","2019-09-16 19:20:11.234000000" "DateTime64(9, 'Europe/Minsk')","2019-09-16 19:20:11.234000000"
------------------------------------------ ------------------------------------------
SELECT formatDateTime(N, \'%C %d %D %e %F %H %I %j %m %M %p %R %S %T %u %V %w %y %Y %%\') SELECT formatDateTime(N, \'%C %d %D %e %F %H %I %j %m %M %p %R %S %T %u %V %w %y %Y %%\')
"String","20 16 09/16/19 16 2019-09-16 00 12 259 09 00 AM 00:00 00 00:00:00 1 38 1 19 2019 %" "String","20 16 09/16/19 16 2019-09-16 00 12 259 09 00 AM 00:00 00 00:00:00 1 38 1 19 2019 %"