mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-23 08:02:02 +00:00
dbms: allowed to compare Date and DateTime with strings in IN [#METR-2944].
This commit is contained in:
parent
26813667eb
commit
5c7dccebc1
@ -336,11 +336,37 @@ static Field convertToType(const Field & src, const IDataType & type)
|
||||
}
|
||||
else if (is_date || is_datetime)
|
||||
{
|
||||
if (src.getType() != Field::Types::UInt64)
|
||||
if (src.getType() == Field::Types::UInt64)
|
||||
return src;
|
||||
|
||||
if (src.getType() == Field::Types::String)
|
||||
{
|
||||
/// Возможность сравнивать даты и даты-с-временем со строкой.
|
||||
const String & str = src.get<const String &>();
|
||||
ReadBufferFromString in(str);
|
||||
|
||||
if (is_date)
|
||||
{
|
||||
DayNum_t date{};
|
||||
readDateText(date, in);
|
||||
if (!in.eof())
|
||||
throw Exception("String is too long for Date: " + str);
|
||||
|
||||
return Field(UInt64(date));
|
||||
}
|
||||
else
|
||||
{
|
||||
time_t date_time{};
|
||||
readDateTimeText(date_time, in);
|
||||
if (!in.eof())
|
||||
throw Exception("String is too long for DateTime: " + str);
|
||||
|
||||
return Field(UInt64(date_time));
|
||||
}
|
||||
}
|
||||
|
||||
throw Exception("Type mismatch in IN section: " + type.getName() + " at left, "
|
||||
+ Field::Types::toString(src.getType()) + " at right");
|
||||
|
||||
return src;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -0,0 +1,8 @@
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
1
|
@ -0,0 +1,8 @@
|
||||
SELECT toDate('2015-02-05') IN ('2015-02-04', '2015-02-05');
|
||||
SELECT toDate('2015-02-05') IN ('2015-02-04', '2015-02-06');
|
||||
SELECT toDateTime('2015-02-03 04:05:06') IN ('2015-02-03 04:05:06', '2015-02-03 05:06:07');
|
||||
SELECT toDateTime('2015-02-03 04:05:06') IN ('2015-02-04 04:05:06', '2015-02-03 05:06:07');
|
||||
SELECT toDate('2015-02-05') NOT IN ('2015-02-04', '2015-02-05');
|
||||
SELECT toDate('2015-02-05') NOT IN ('2015-02-04', '2015-02-06');
|
||||
SELECT toDateTime('2015-02-03 04:05:06') NOT IN ('2015-02-03 04:05:06', '2015-02-03 05:06:07');
|
||||
SELECT toDateTime('2015-02-03 04:05:06') NOT IN ('2015-02-04 04:05:06', '2015-02-03 05:06:07');
|
Loading…
Reference in New Issue
Block a user