ClickHouse/tests/queries/0_stateless/02668_parse_datetime.reference

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

273 lines
14 KiB
Plaintext
Raw Normal View History

2023-02-28 07:23:29 +00:00
-- { echoOn }
-- year
2023-03-22 11:25:37 +00:00
select parseDateTime('2020', '%Y', 'UTC') = toDateTime('2020-01-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
-- month
2023-03-23 03:08:04 +00:00
select parseDateTime('02', '%m', 'UTC') = toDateTime('2000-02-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('07', '%m', 'UTC') = toDateTime('2000-07-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('11-', '%m-', 'UTC') = toDateTime('2000-11-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-07 06:35:50 +00:00
select parseDateTime('00', '%m'); -- { serverError CANNOT_PARSE_DATETIME }
select parseDateTime('13', '%m'); -- { serverError CANNOT_PARSE_DATETIME }
select parseDateTime('12345', '%m'); -- { serverError CANNOT_PARSE_DATETIME }
2023-03-23 03:08:04 +00:00
select parseDateTime('02', '%c', 'UTC') = toDateTime('2000-02-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('07', '%c', 'UTC') = toDateTime('2000-07-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('11-', '%c-', 'UTC') = toDateTime('2000-11-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-07 06:35:50 +00:00
select parseDateTime('00', '%c'); -- { serverError CANNOT_PARSE_DATETIME }
select parseDateTime('13', '%c'); -- { serverError CANNOT_PARSE_DATETIME }
select parseDateTime('12345', '%c'); -- { serverError CANNOT_PARSE_DATETIME }
2023-03-23 03:08:04 +00:00
select parseDateTime('jun', '%b', 'UTC') = toDateTime('2000-06-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('JUN', '%b', 'UTC') = toDateTime('2000-06-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-07 06:35:50 +00:00
select parseDateTime('abc', '%b'); -- { serverError CANNOT_PARSE_DATETIME }
2023-04-05 12:25:51 +00:00
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 }
2023-04-05 12:25:51 +00:00
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;
2023-02-28 07:23:29 +00:00
-- day of month
2023-03-23 03:08:04 +00:00
select parseDateTime('07', '%d', 'UTC') = toDateTime('2000-01-07', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('01', '%d', 'UTC') = toDateTime('2000-01-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('/11', '/%d', 'UTC') = toDateTime('2000-01-11', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-07 06:35:50 +00:00
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
2023-03-23 03:08:04 +00:00
select parseDateTime('01 31 20 02', '%m %d %d %m', 'UTC') = toDateTime('2000-02-20', 'UTC');
2023-03-07 06:35:50 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('02 31 20 04', '%m %d %d %m', 'UTC') = toDateTime('2000-04-20', 'UTC');
2023-03-07 06:35:50 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('02 31 01', '%m %d %m', 'UTC') = toDateTime('2000-01-31', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('2000-02-29', '%Y-%m-%d', 'UTC') = toDateTime('2000-02-29', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-07 06:35:50 +00:00
select parseDateTime('2001-02-29', '%Y-%m-%d'); -- { serverError CANNOT_PARSE_DATETIME }
2023-02-28 07:23:29 +00:00
-- day of year
2023-03-23 03:08:04 +00:00
select parseDateTime('001', '%j', 'UTC') = toDateTime('2000-01-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('007', '%j', 'UTC') = toDateTime('2000-01-07', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('/031/', '/%j/', 'UTC') = toDateTime('2000-01-31', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('032', '%j', 'UTC') = toDateTime('2000-02-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('060', '%j', 'UTC') = toDateTime('2000-02-29', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('365', '%j', 'UTC') = toDateTime('2000-12-30', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('366', '%j', 'UTC') = toDateTime('2000-12-31', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('1980 001', '%Y %j', 'UTC') = toDateTime('1980-01-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('1980 007', '%Y %j', 'UTC') = toDateTime('1980-01-07', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('1980 /007', '%Y /%j', 'UTC') = toDateTime('1980-01-07', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('1980 /031/', '%Y /%j/', 'UTC') = toDateTime('1980-01-31', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('1980 032', '%Y %j', 'UTC') = toDateTime('1980-02-01', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('1980 060', '%Y %j', 'UTC') = toDateTime('1980-02-29', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-23 03:08:04 +00:00
select parseDateTime('1980 366', '%Y %j', 'UTC') = toDateTime('1980-12-31', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-07 06:35:50 +00:00
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 }
2023-03-23 03:08:04 +00:00
select parseDateTime('2001 366 2000', '%Y %j %Y', 'UTC') = toDateTime('2000-12-31', 'UTC');
2023-02-28 07:23:29 +00:00
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
2023-03-07 06:35:50 +00:00
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 }
2023-02-28 07:23:29 +00:00
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
2023-03-07 06:35:50 +00:00
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 }
2023-02-28 07:23:29 +00:00
-- hour of half day
select parseDateTime('07', '%h', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
1
2023-03-01 03:02:41 +00:00
select parseDateTime('12', '%h', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
2023-02-28 07:23:29 +00:00
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
2023-03-07 06:35:50 +00:00
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 }
2023-02-28 07:23:29 +00:00
select parseDateTime('07', '%I', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
1
2023-03-01 03:02:41 +00:00
select parseDateTime('12', '%I', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
2023-02-28 07:23:29 +00:00
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
2023-03-07 06:35:50 +00:00
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 }
2023-02-28 07:23:29 +00:00
select parseDateTime('07', '%l', 'UTC') = toDateTime('1970-01-01 07:00:00', 'UTC');
1
2023-03-01 03:02:41 +00:00
select parseDateTime('12', '%l', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
2023-02-28 07:23:29 +00:00
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
2023-03-07 06:35:50 +00:00
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 }
2023-02-28 07:23:29 +00:00
-- 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
2023-03-01 03:02:41 +00:00
select parseDateTime('12 PM', '%h %p', 'UTC') = toDateTime('1970-01-01 12:00:00', 'UTC');
2023-02-28 07:23:29 +00:00
1
2023-03-01 03:02:41 +00:00
select parseDateTime('12 AM', '%h %p', 'UTC') = toDateTime('1970-01-01 00:00:00', 'UTC');
2023-02-28 07:23:29 +00:00
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
2023-03-07 06:35:50 +00:00
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 }
2023-02-28 07:23:29 +00:00
-- 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
2023-03-07 06:35:50 +00:00
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 }
2023-02-28 07:23:29 +00:00
-- mixed YMD format
2023-04-06 08:40:39 +00:00
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');
2023-02-28 07:23:29 +00:00
1
2023-04-06 08:40:39 +00:00
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');
2023-02-28 07:23:29 +00:00
1
2023-04-06 08:40:39 +00:00
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');
2023-02-28 07:23:29 +00:00
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 }
2023-08-23 20:08:27 +00:00
-- 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
2023-11-27 10:44:26 +00:00
-- %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
2023-11-27 10:44:26 +00:00
-- %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
2023-11-27 10:44:26 +00:00
-- %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