mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-09 16:02:23 +00:00
273 lines
14 KiB
Plaintext
273 lines
14 KiB
Plaintext
-- { echoOn }
|
|
-- year
|
|
select parseDateTime('2020', '%Y', 'UTC') = toDateTime('2020-01-01', 'UTC');
|
|
1
|
|
-- month
|
|
select parseDateTime('02', '%m', 'UTC') = toDateTime('2000-02-01', 'UTC');
|
|
1
|
|
select parseDateTime('07', '%m', 'UTC') = toDateTime('2000-07-01', 'UTC');
|
|
1
|
|
select parseDateTime('11-', '%m-', 'UTC') = toDateTime('2000-11-01', 'UTC');
|
|
1
|
|
select parseDateTime('00', '%m'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('13', '%m'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('12345', '%m'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('02', '%c', 'UTC') = toDateTime('2000-02-01', 'UTC');
|
|
1
|
|
select parseDateTime('07', '%c', 'UTC') = toDateTime('2000-07-01', 'UTC');
|
|
1
|
|
select parseDateTime('11-', '%c-', 'UTC') = toDateTime('2000-11-01', 'UTC');
|
|
1
|
|
select parseDateTime('00', '%c'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('13', '%c'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('12345', '%c'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('jun', '%b', 'UTC') = toDateTime('2000-06-01', 'UTC');
|
|
1
|
|
select parseDateTime('JUN', '%b', 'UTC') = toDateTime('2000-06-01', 'UTC');
|
|
1
|
|
select parseDateTime('abc', '%b'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
set formatdatetime_parsedatetime_m_is_month_name = 1;
|
|
select parseDateTime('may', '%M', 'UTC') = toDateTime('2000-05-01', 'UTC');
|
|
1
|
|
select parseDateTime('MAY', '%M', 'UTC') = toDateTime('2000-05-01', 'UTC');
|
|
1
|
|
select parseDateTime('september', '%M', 'UTC') = toDateTime('2000-09-01', 'UTC');
|
|
1
|
|
select parseDateTime('summer', '%M'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
set formatdatetime_parsedatetime_m_is_month_name = 0;
|
|
select parseDateTime('08', '%M', 'UTC') = toDateTime('1970-01-01 00:08:00', 'UTC');
|
|
1
|
|
select parseDateTime('59', '%M', 'UTC') = toDateTime('1970-01-01 00:59:00', 'UTC');
|
|
1
|
|
select parseDateTime('00/', '%M/', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('60', '%M', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('-1', '%M', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('123456789', '%M', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
set formatdatetime_parsedatetime_m_is_month_name = 1;
|
|
-- day of month
|
|
select parseDateTime('07', '%d', 'UTC') = toDateTime('2000-01-07', 'UTC');
|
|
1
|
|
select parseDateTime('01', '%d', 'UTC') = toDateTime('2000-01-01', 'UTC');
|
|
1
|
|
select parseDateTime('/11', '/%d', 'UTC') = toDateTime('2000-01-11', 'UTC');
|
|
1
|
|
select parseDateTime('00', '%d'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('32', '%d'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('12345', '%d'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('02-31', '%m-%d'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('04-31', '%m-%d'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
-- The last one is chosen if multiple months of year if supplied
|
|
select parseDateTime('01 31 20 02', '%m %d %d %m', 'UTC') = toDateTime('2000-02-20', 'UTC');
|
|
1
|
|
select parseDateTime('02 31 20 04', '%m %d %d %m', 'UTC') = toDateTime('2000-04-20', 'UTC');
|
|
1
|
|
select parseDateTime('02 31 01', '%m %d %m', 'UTC') = toDateTime('2000-01-31', 'UTC');
|
|
1
|
|
select parseDateTime('2000-02-29', '%Y-%m-%d', 'UTC') = toDateTime('2000-02-29', 'UTC');
|
|
1
|
|
select parseDateTime('2001-02-29', '%Y-%m-%d'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
-- day of year
|
|
select parseDateTime('001', '%j', 'UTC') = toDateTime('2000-01-01', 'UTC');
|
|
1
|
|
select parseDateTime('007', '%j', 'UTC') = toDateTime('2000-01-07', 'UTC');
|
|
1
|
|
select parseDateTime('/031/', '/%j/', 'UTC') = toDateTime('2000-01-31', 'UTC');
|
|
1
|
|
select parseDateTime('032', '%j', 'UTC') = toDateTime('2000-02-01', 'UTC');
|
|
1
|
|
select parseDateTime('060', '%j', 'UTC') = toDateTime('2000-02-29', 'UTC');
|
|
1
|
|
select parseDateTime('365', '%j', 'UTC') = toDateTime('2000-12-30', 'UTC');
|
|
1
|
|
select parseDateTime('366', '%j', 'UTC') = toDateTime('2000-12-31', 'UTC');
|
|
1
|
|
select parseDateTime('1980 001', '%Y %j', 'UTC') = toDateTime('1980-01-01', 'UTC');
|
|
1
|
|
select parseDateTime('1980 007', '%Y %j', 'UTC') = toDateTime('1980-01-07', 'UTC');
|
|
1
|
|
select parseDateTime('1980 /007', '%Y /%j', 'UTC') = toDateTime('1980-01-07', 'UTC');
|
|
1
|
|
select parseDateTime('1980 /031/', '%Y /%j/', 'UTC') = toDateTime('1980-01-31', 'UTC');
|
|
1
|
|
select parseDateTime('1980 032', '%Y %j', 'UTC') = toDateTime('1980-02-01', 'UTC');
|
|
1
|
|
select parseDateTime('1980 060', '%Y %j', 'UTC') = toDateTime('1980-02-29', 'UTC');
|
|
1
|
|
select parseDateTime('1980 366', '%Y %j', 'UTC') = toDateTime('1980-12-31', 'UTC');
|
|
1
|
|
select parseDateTime('1981 366', '%Y %j'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('367', '%j'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('000', '%j'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
-- The last one is chosen if multiple day of years are supplied.
|
|
select parseDateTime('2000 366 2001', '%Y %j %Y'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('2001 366 2000', '%Y %j %Y', 'UTC') = toDateTime('2000-12-31', 'UTC');
|
|
1
|
|
-- hour of day
|
|
select parseDateTime('07', '%H', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('23', '%H', 'UTC') = toDateTime('1970-01-01 23:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00', '%H', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('10', '%H', 'UTC') = toDateTime('1970-01-01 10:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('24', '%H', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('-1', '%H', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('1234567', '%H', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('07', '%k', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('23', '%k', 'UTC') = toDateTime('1970-01-01 23:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00', '%k', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('10', '%k', 'UTC') = toDateTime('1970-01-01 10:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('24', '%k', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('-1', '%k', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('1234567', '%k', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
-- hour of half day
|
|
select parseDateTime('07', '%h', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('12', '%h', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('01', '%h', 'UTC') = toDateTime('1970-01-01 01:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('10', '%h', 'UTC') = toDateTime('1970-01-01 10:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00', '%h', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('13', '%h', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('123456789', '%h', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('07', '%I', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('12', '%I', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('01', '%I', 'UTC') = toDateTime('1970-01-01 01:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('10', '%I', 'UTC') = toDateTime('1970-01-01 10:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00', '%I', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('13', '%I', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('123456789', '%I', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('07', '%l', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('12', '%l', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('01', '%l', 'UTC') = toDateTime('1970-01-01 01:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('10', '%l', 'UTC') = toDateTime('1970-01-01 10:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00', '%l', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('13', '%l', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('123456789', '%l', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
-- half of day
|
|
select parseDateTime('07 PM', '%H %p', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('07 AM', '%H %p', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('07 pm', '%H %p', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('07 am', '%H %p', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00 AM', '%H %p', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00 PM', '%H %p', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00 am', '%H %p', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('00 pm', '%H %p', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('01 PM', '%h %p', 'UTC') = toDateTime('1970-01-01 13:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('01 AM', '%h %p', 'UTC') = toDateTime('1970-01-01 01:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('06 PM', '%h %p', 'UTC') = toDateTime('1970-01-01 18:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('06 AM', '%h %p', 'UTC') = toDateTime('1970-01-01 06:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('12 PM', '%h %p', 'UTC') = toDateTime('1970-01-01 12:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('12 AM', '%h %p', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
-- minute
|
|
select parseDateTime('08', '%i', 'UTC') = toDateTime('1970-01-01 00:08:00', 'UTC');
|
|
1
|
|
select parseDateTime('59', '%i', 'UTC') = toDateTime('1970-01-01 00:59:00', 'UTC');
|
|
1
|
|
select parseDateTime('00/', '%i/', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('60', '%i', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('-1', '%i', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('123456789', '%i', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
-- second
|
|
select parseDateTime('09', '%s', 'UTC') = toDateTime('1970-01-01 00:00:09', 'UTC');
|
|
1
|
|
select parseDateTime('58', '%s', 'UTC') = toDateTime('1970-01-01 00:00:58', 'UTC');
|
|
1
|
|
select parseDateTime('00/', '%s/', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('60', '%s', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('-1', '%s', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('123456789', '%s', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
-- microsecond
|
|
select parseDateTime('000000', '%f', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('456789', '%f', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('42', '%f', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC'); -- { serverError NOT_ENOUGH_SPACE }
|
|
select parseDateTime('12ABCD', '%f', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
-- mixed YMD format
|
|
select parseDateTime('2021-01-04+23:00:00.654321', '%Y-%m-%d+%H:%i:%s.%f', 'UTC') = toDateTime('2021-01-04 23:00:00', 'UTC');
|
|
1
|
|
select parseDateTime('2019-07-03 11:04:10.975319', '%Y-%m-%d %H:%i:%s.%f', 'UTC') = toDateTime('2019-07-03 11:04:10', 'UTC');
|
|
1
|
|
select parseDateTime('10:04:11 03-07-2019.242424', '%s:%i:%H %d-%m-%Y.%f', 'UTC') = toDateTime('2019-07-03 11:04:10', 'UTC');
|
|
1
|
|
-- *OrZero, *OrNull, str_to_date
|
|
select parseDateTimeOrZero('10:04:11 03-07-2019', '%s:%i:%H %d-%m-%Y', 'UTC') = toDateTime('2019-07-03 11:04:10', 'UTC');
|
|
1
|
|
select parseDateTimeOrZero('10:04:11 invalid 03-07-2019', '%s:%i:%H %d-%m-%Y', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
|
|
1
|
|
select parseDateTimeOrNull('10:04:11 03-07-2019', '%s:%i:%H %d-%m-%Y', 'UTC') = toDateTime('2019-07-03 11:04:10', 'UTC');
|
|
1
|
|
select parseDateTimeOrNull('10:04:11 invalid 03-07-2019', '%s:%i:%H %d-%m-%Y', 'UTC') IS NULL;
|
|
1
|
|
select str_to_date('10:04:11 03-07-2019', '%s:%i:%H %d-%m-%Y', 'UTC') = toDateTime('2019-07-03 11:04:10', 'UTC');
|
|
1
|
|
select sTr_To_DaTe('10:04:11 03-07-2019', '%s:%i:%H %d-%m-%Y', 'UTC') = toDateTime('2019-07-03 11:04:10', 'UTC');
|
|
1
|
|
select str_to_date('10:04:11 invalid 03-07-2019', '%s:%i:%H %d-%m-%Y', 'UTC') IS NULL;
|
|
1
|
|
-- Error handling
|
|
select parseDateTime('12 AM'); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
|
|
select parseDateTime('12 AM', '%h %p', 'UTC', 'a fourth argument'); -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
|
|
-- Fuzzer crash bug #53715
|
|
select parseDateTime('', '', toString(number)) from numbers(13); -- { serverError ILLEGAL_COLUMN }
|
|
-- %h
|
|
select parseDateTime('Aug 13, 2022, 7:58:32 PM', '%b %e, %G, %h:%i:%s %p', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('Aug 13, 2022, 07:58:32 PM', '%b %e, %G, %h:%i:%s %p', 'UTC');
|
|
2022-08-13 19:58:32
|
|
-- %l accepts single or double digits inputs
|
|
select parseDateTime('Aug 13, 2022, 7:58:32 PM', '%b %e, %G, %l:%i:%s %p', 'UTC');
|
|
2022-08-13 19:58:32
|
|
select parseDateTime('Aug 13, 2022, 07:58:32 PM', '%b %e, %G, %l:%i:%s %p', 'UTC');
|
|
2022-08-13 19:58:32
|
|
-- %H
|
|
select parseDateTime('Aug 13, 2022, 7:58:32', '%b %e, %G, %H:%i:%s', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('Aug 13, 2022, 07:58:32', '%b %e, %G, %H:%i:%s', 'UTC');
|
|
2022-08-13 07:58:32
|
|
-- %k accepts single or double digits inputs
|
|
select parseDateTime('Aug 13, 2022, 7:58:32', '%b %e, %G, %k:%i:%s', 'UTC');
|
|
2022-08-13 07:58:32
|
|
select parseDateTime('Aug 13, 2022, 07:58:32', '%b %e, %G, %k:%i:%s', 'UTC');
|
|
2022-08-13 07:58:32
|
|
-- %m
|
|
select parseDateTime('8 13, 2022, 7:58:32', '%m %e, %G, %k:%i:%s', 'UTC'); -- { serverError CANNOT_PARSE_DATETIME }
|
|
select parseDateTime('08 13, 2022, 07:58:32', '%m %e, %G, %k:%i:%s', 'UTC');
|
|
2022-08-13 07:58:32
|
|
-- %c accepts single or double digits inputs
|
|
select parseDateTime('8 13, 2022, 7:58:32', '%c %e, %G, %k:%i:%s', 'UTC');
|
|
2022-08-13 07:58:32
|
|
select parseDateTime('08 13, 2022, 07:58:32', '%c %e, %G, %k:%i:%s', 'UTC');
|
|
2022-08-13 07:58:32
|