Fixed parsing string to DateTime64 for large values.

Before fix:
SELECT toDateTime64('2201-01-12 12:12:12', 3, 'UTC')
1970-03-26 09:10:48.237

After fix:
SELECT toDateTime64('2201-01-12 12:12:12', 3, 'UTC')
2201-01-12 12:12:12.000
This commit is contained in:
Vasily Nemkov 2021-04-09 19:22:53 +03:00
parent 4dcc1b2d2e
commit c882d290bd
5 changed files with 22 additions and 4 deletions

View File

@ -773,7 +773,8 @@ inline ReturnType readDateTimeTextImpl(DateTime64 & datetime64, UInt32 scale, Re
while (!buf.eof() && isNumericASCII(*buf.position()))
++buf.position();
}
else if (scale && (whole >= 1000000000LL * scale))
//9908870400 is time_t value for 2084-01-01 UTC (a bit over the last year supported by DateTime64)
else if (scale && scale < 18 && (whole >= 9908870400LL * static_cast<int64_t>(intExp10(scale))))
{
/// Unix timestamp with subsecond precision, already scaled to integer.
/// For disambiguation we support only time since 2001-09-09 01:46:40 UTC and less than 30 000 years in future.

View File

@ -23,5 +23,5 @@ SELECT formatDateTime(toDateTime64('2019-09-16 19:20:12', 0, 'Europe/Moscow'), '
20
SELECT formatDateTime(toDateTime64('2105-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
21
SELECT formatDateTime(toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
19
SELECT formatDateTime(toDateTime64('2205-01-12 12:12:12', 6, 'Europe/Moscow'), '%C');
22

View File

@ -13,4 +13,4 @@ SELECT formatDateTime(toDateTime64('1969-12-12 12:12:12', 6, 'Europe/Moscow'), '
SELECT formatDateTime(toDateTime64('1989-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2019-09-16 19:20:12', 0, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2105-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow'), '%C');
SELECT formatDateTime(toDateTime64('2205-01-12 12:12:12', 6, 'Europe/Moscow'), '%C');

View File

@ -0,0 +1,10 @@
-- { echo }
SELECT toDateTime64('2205-12-12 12:12:12', 0, 'UTC');
2205-12-12 12:12:12
SELECT toDateTime64('2205-12-12 12:12:12', 0, 'Europe/Moscow');
2205-12-12 12:12:12
SELECT toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow');
2205-12-12 12:12:12.000000
SELECT toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow');
2205-12-12 12:12:12.000000

View File

@ -0,0 +1,7 @@
-- { echo }
SELECT toDateTime64('2205-12-12 12:12:12', 0, 'UTC');
SELECT toDateTime64('2205-12-12 12:12:12', 0, 'Europe/Moscow');
SELECT toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow');
SELECT toDateTime64('2205-12-12 12:12:12', 6, 'Europe/Moscow');