Fixed comparing Date and DateTime64

This commit is contained in:
Vasily Nemkov 2020-12-08 17:17:02 +03:00
parent 5556c48298
commit 0c2d73adcb
3 changed files with 50 additions and 1 deletions

View File

@ -1216,7 +1216,10 @@ public:
{ {
return res; return res;
} }
else if (isColumnedAsDecimal(left_type) || isColumnedAsDecimal(right_type)) else if ((isColumnedAsDecimal(left_type) || isColumnedAsDecimal(right_type))
// Comparing Date and DateTime64 requires implicit conversion,
// otherwise Date is treated as number.
&& !(date_and_datetime && (isDate(left_type) || isDate(right_type))))
{ {
// compare // compare
if (!allowDecimalComparison(left_type, right_type) && !date_and_datetime) if (!allowDecimalComparison(left_type, right_type) && !date_and_datetime)

View File

@ -0,0 +1,3 @@
-1 DateTime64(1, \'UTC\') < 1 1 1 <= 1 1 1 = 0 0 0 >= 0 0 0 > 0 0 0 != 1 1 1
0 DateTime64(1, \'UTC\') < 0 0 0 <= 0 1 0 = 0 1 0 >= 1 1 1 > 1 0 1 != 1 0 1
1 DateTime64(1, \'UTC\') < 0 0 0 <= 0 0 0 = 0 0 0 >= 1 1 1 > 1 1 1 != 1 1 1

View File

@ -0,0 +1,43 @@
SELECT
n,
toTypeName(dt64) AS dt64_typename,
'<',
dt64 < d,
toDate(dt64) < d,
dt64 < toDateTime64(d, 1, 'UTC'),
'<=',
dt64 <= d,
toDate(dt64) <= d,
dt64 <= toDateTime64(d, 1, 'UTC'),
'=',
dt64 = d,
toDate(dt64) = d,
dt64 = toDateTime64(d, 1, 'UTC'),
'>=',
dt64 >= d,
toDate(dt64) >= d,
dt64 >= toDateTime64(d, 1, 'UTC'),
'>',
dt64 > d,
toDate(dt64) > d,
dt64 > toDateTime64(d, 1, 'UTC'),
'!=',
dt64 != d,
toDate(dt64) != d,
dt64 != toDateTime64(d, 1, 'UTC')
FROM
(
SELECT
number - 1 as n,
toDateTime64(toStartOfInterval(now(), toIntervalSecond(1), 'UTC'), 1, 'UTC') AS dt64,
toDate(now(), 'UTC') - n as d
FROM system.numbers
LIMIT 3
)
FORMAT TabSeparated