mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 09:32:01 +00:00
Merge pull request #56286 from bigo-sg/ch_56285
Fix inconsistency of "cast('0' as DateTime64(3))" and "cast('0' as Nullable(DateTime64(3)))"
This commit is contained in:
commit
653a51a862
@ -984,20 +984,31 @@ inline ReturnType readDateTimeTextImpl(time_t & datetime, ReadBuffer & buf, cons
|
||||
template <typename ReturnType>
|
||||
inline ReturnType readDateTimeTextImpl(DateTime64 & datetime64, UInt32 scale, ReadBuffer & buf, const DateLUTImpl & date_lut)
|
||||
{
|
||||
static constexpr bool throw_exception = std::is_same_v<ReturnType, void>;
|
||||
|
||||
time_t whole = 0;
|
||||
bool is_negative_timestamp = (!buf.eof() && *buf.position() == '-');
|
||||
bool is_empty = buf.eof();
|
||||
|
||||
if (!is_empty)
|
||||
{
|
||||
try
|
||||
if constexpr (throw_exception)
|
||||
{
|
||||
readDateTimeTextImpl<ReturnType, true>(whole, buf, date_lut);
|
||||
try
|
||||
{
|
||||
readDateTimeTextImpl<ReturnType, true>(whole, buf, date_lut);
|
||||
}
|
||||
catch (const DB::ParsingException &)
|
||||
{
|
||||
if (buf.eof() || *buf.position() != '.')
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (const DB::ParsingException & exception)
|
||||
else
|
||||
{
|
||||
if (buf.eof() || *buf.position() != '.')
|
||||
throw exception;
|
||||
auto ok = readDateTimeTextImpl<ReturnType, true>(whole, buf, date_lut);
|
||||
if (!ok && (buf.eof() || *buf.position() != '.'))
|
||||
return ReturnType(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
1969-12-31 23:57:57.000
|
||||
1970-01-01 00:00:23.900
|
||||
1969-12-31 23:59:36.100
|
||||
\N
|
||||
\N
|
||||
|
@ -2,4 +2,9 @@ SELECT toDateTime64('-123', 3, 'UTC'); -- Allowed: no year starts with '-'
|
||||
SELECT toDateTime64('23.9', 3, 'UTC'); -- Allowed: no year has a dot in notation
|
||||
SELECT toDateTime64('-23.9', 3, 'UTC'); -- Allowed
|
||||
|
||||
SELECT toDateTime64('1234', 3, 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
||||
SELECT toDateTime64OrNull('0', 3, 'UTC');
|
||||
SELECT cast('0' as Nullable(DateTime64(3, 'UTC')));
|
||||
|
||||
SELECT toDateTime64('1234', 3, 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
||||
SELECT toDateTime64('0', 3, 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
||||
SELECT cast('0' as DateTime64(3, 'UTC')); -- { serverError CANNOT_PARSE_DATETIME }
|
||||
|
Loading…
Reference in New Issue
Block a user