-
Notifications
You must be signed in to change notification settings - Fork 8.3k
toDate and toDateTime shouldn't overflow, but instead overflow and at different values for integer vs string parameters #17354
Copy link
Copy link
Closed
Labels
Description
Describe the bug
Using toDate and toDateTime with a formatted string in the far-future gives different results than when using it with an integer, overflowing at different points.
How to reproduce
-
ClickHouse server version:
20.9.2.20 -
Queries to run that lead to unexpected result:
-- toDateTime with an integer
select toDateTime(4294967294); -- 2106-02-06 23:28:14
select toDateTime(4294967295); -- 2106-02-06 23:28:15
select toDateTime(4294967296); -- 2106-02-06 23:28:15 -- not correct, but better than overflowing
select toDateTime(4323283200); -- 2106-02-06 23:28:15 -- not correct, but better than overflowing
select toDateTime(5680281650); -- 2106-02-06 23:28:15 -- not correct, but better than overflowing
select toDateTime(9223372036854775807); -- 2106-02-06 23:28:15 -- not correct, but better than overflowing
select toDateTime(9223372036854775808); -- 1969-12-31 17:00:00 -- overflow
-- toDateTime with a string
select toDateTime('2106-02-06 06:28:14'); -- 2106-02-05 23:28:14
select toDateTime('2106-02-06 06:28:15'); -- 2106-02-05 23:28:15
select toDateTime('2106-02-06 06:28:16'); -- 1969-12-31 17:00:00 -- overflow-- toDate with an integer
select toDate(49709); -- 2106-02-06
select toDate(49710); -- 2106-02-07
select toDate(49711); -- 2106-02-07 -- not correct, but better than overflowing
select toDate(50000); -- 2106-02-07 -- not correct, but better than overflowing
select toDate(65535); -- 2106-02-07 -- not correct, but better than overflowing
select toDate(65536); -- 1970-01-01 -- overflow
-- toDate with a string
select toDate('2106-02-06'); -- 2106-02-06
select toDate('2106-02-07'); -- 2106-02-07
select toDate('2106-02-08'); -- 2106-02-07 -- not correct, but better than overflowing
select toDate('2106-12-31'); -- 2106-02-07 -- not correct, but better than overflowing
select toDate('2107-01-01'); -- 1970-01-01 -- overflowExpected behavior
I would expect that instead of overflowing, any parameter that results in a date / datetime greater than the max would give back the maximum date / datetime.
Reactions are currently unavailable