Skip to content

Commit

Permalink
Merge pull request #61753 from ClickHouse/backport/23.3/61561
Browse files Browse the repository at this point in the history
Backport #61561 to 23.3: Fix addDays cause an error when used datetime64
  • Loading branch information
antaljanosbenjamin committed Mar 26, 2024
2 parents 4e26300 + 271e44b commit b2d6234
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Functions/FunctionDateOrDateTimeAddInterval.h
Expand Up @@ -544,14 +544,14 @@ class FunctionDateOrDateTimeAddInterval : public IFunction
}
else
{
if (!WhichDataType(arguments[0].type).isDateTime()
if (!(isDateTime(arguments[0].type) || isDateTime64(arguments[0].type))
|| !WhichDataType(arguments[2].type).isString())
{
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Function {} supports 2 or 3 arguments. "
"The 1st argument must be of type Date or DateTime. "
"The 1st argument must be of type Date, DateTime or DateTime64. "
"The 2nd argument must be a number. "
"The 3rd argument (optional) must be a constant string with timezone name. "
"The timezone argument is allowed only when the 1st argument has the type DateTime",
"The timezone argument is allowed only when the 1st argument has the type DateTime or DateTime64",
getName());
}
}
Expand Down
Expand Up @@ -241,82 +241,82 @@ SELECT toYYYYMMDDhhmmss(N, \'Asia/Istanbul\')
SELECT addYears(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2020-09-16 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2020-09-16 19:20:11.234"
------------------------------------------
SELECT addMonths(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-10-16 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-10-16 19:20:11.234"
------------------------------------------
SELECT addWeeks(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-23 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-23 19:20:11.234"
------------------------------------------
SELECT addDays(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-17 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-17 19:20:11.234"
------------------------------------------
SELECT addHours(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-16 20:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-16 20:20:11.234"
------------------------------------------
SELECT addMinutes(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-16 19:21:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-16 19:21:11.234"
------------------------------------------
SELECT addSeconds(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-16 19:20:12"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-16 19:20:12.234"
------------------------------------------
SELECT addQuarters(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-12-16 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-12-16 19:20:11.234"
------------------------------------------
SELECT subtractYears(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2018-09-16 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2018-09-16 19:20:11.234"
------------------------------------------
SELECT subtractMonths(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-08-16 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-08-16 19:20:11.234"
------------------------------------------
SELECT subtractWeeks(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-09 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-09 19:20:11.234"
------------------------------------------
SELECT subtractDays(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-15 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-15 19:20:11.234"
------------------------------------------
SELECT subtractHours(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-16 18:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-16 18:20:11.234"
------------------------------------------
SELECT subtractMinutes(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-16 19:19:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-16 19:19:11.234"
------------------------------------------
SELECT subtractSeconds(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-09-16 19:20:10"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-09-16 19:20:10.234"
------------------------------------------
SELECT subtractQuarters(N, 1, \'Asia/Istanbul\')
Code: 43
"DateTime('Asia/Istanbul')","2019-06-16 19:20:11"
Code: 43
"DateTime64(3, 'Asia/Istanbul')","2019-06-16 19:20:11.234"
------------------------------------------
SELECT CAST(N as DateTime(\'Europe/Minsk\'))
"DateTime('Europe/Minsk')","2019-09-16 00:00:00"
Expand Down
@@ -0,0 +1 @@
2024-01-11 00:00:00.000000
1 change: 1 addition & 0 deletions tests/queries/0_stateless/03013_addDays_with_timezone.sql
@@ -0,0 +1 @@
select addDays(toDateTime64('2024-01-01', 6, 'Asia/Shanghai'), 10, 'Asia/Shanghai');

0 comments on commit b2d6234

Please sign in to comment.