mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Merge pull request #18050 from Enmk/DateTime64_DateTime_comparison
Fixed Date vs DateTime64 comparison
This commit is contained in:
commit
7985ed9778
@ -1216,7 +1216,10 @@ public:
|
||||
{
|
||||
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
|
||||
if (!allowDecimalComparison(left_type, right_type) && !date_and_datetime)
|
||||
|
@ -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 <= 1 1 1 = 1 1 1 >= 1 1 1 > 0 0 0 != 0 0 0
|
||||
1 DateTime64(1, \'UTC\') < 0 0 0 <= 0 0 0 = 0 0 0 >= 1 1 1 > 1 1 1 != 1 1 1
|
@ -0,0 +1,43 @@
|
||||
SELECT
|
||||
n,
|
||||
toTypeName(dt64) AS dt64_typename,
|
||||
|
||||
'<',
|
||||
dt64 < dt,
|
||||
toDateTime(dt64) < dt,
|
||||
dt64 < toDateTime64(dt, 1, 'UTC'),
|
||||
|
||||
'<=',
|
||||
dt64 <= dt,
|
||||
toDateTime(dt64) <= dt,
|
||||
dt64 <= toDateTime64(dt, 1, 'UTC'),
|
||||
|
||||
'=',
|
||||
dt64 = dt,
|
||||
toDateTime(dt64) = dt,
|
||||
dt64 = toDateTime64(dt, 1, 'UTC'),
|
||||
|
||||
'>=',
|
||||
dt64 >= dt,
|
||||
toDateTime(dt64) >= dt,
|
||||
dt64 >= toDateTime64(dt, 1, 'UTC'),
|
||||
|
||||
'>',
|
||||
dt64 > dt,
|
||||
toDateTime(dt64) > dt,
|
||||
dt64 > toDateTime64(dt, 1, 'UTC'),
|
||||
|
||||
'!=',
|
||||
dt64 != dt,
|
||||
toDateTime(dt64) != dt,
|
||||
dt64 != toDateTime64(dt, 1, 'UTC')
|
||||
FROM
|
||||
(
|
||||
WITH toDateTime('2015-05-18 07:40:11') as value
|
||||
SELECT
|
||||
number - 1 as n,
|
||||
toDateTime64(value, 1, 'UTC') AS dt64,
|
||||
value - n as dt
|
||||
FROM system.numbers
|
||||
LIMIT 3
|
||||
)
|
@ -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
|
@ -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
|
||||
(
|
||||
WITH toDateTime('2019-09-16 19:20:11') as val
|
||||
SELECT
|
||||
number - 1 as n,
|
||||
toDateTime64(val, 1, 'UTC') AS dt64,
|
||||
toDate(val, 'UTC') - n as d
|
||||
FROM system.numbers
|
||||
LIMIT 3
|
||||
)
|
Loading…
Reference in New Issue
Block a user