fix parseDateTimeBestEffortOrNull with empty string

This commit is contained in:
feng lv 2020-10-30 05:42:10 +00:00
parent 19794bee07
commit f428675b6e
3 changed files with 20 additions and 0 deletions

View File

@ -533,6 +533,10 @@ ReturnType parseDateTimeBestEffortImpl(
}
}
/// If neigher Date nor Time is parsed successfully, it should fail
if (!year && !month && !day_of_month && !has_time)
return on_error("Cannot read DateTime: neither Date nor Time was parsed successfully", ErrorCodes::CANNOT_PARSE_DATETIME);
if (!year)
year = 2000;
if (!month)

View File

@ -0,0 +1,8 @@
2010-01-01 00:00:00
2010-01-01 01:01:01
2000-01-01 01:01:01
\N
\N
\N
\N
\N

View File

@ -0,0 +1,8 @@
SELECT parseDateTimeBestEffortOrNull('2010-01-01');
SELECT parseDateTimeBestEffortOrNull('2010-01-01 01:01:01');
SELECT parseDateTimeBestEffortOrNull('01:01:01');
SELECT parseDateTimeBestEffortOrNull('20100');
SELECT parseDateTimeBestEffortOrNull('0100:0100:0000');
SELECT parseDateTimeBestEffortOrNull('x');
SELECT parseDateTimeBestEffortOrNull('');
SELECT parseDateTimeBestEffortOrNull(' ');