ClickHouse/tests/queries/0_stateless/02403_date_time_narrowing.sql

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

75 lines
3.7 KiB
MySQL
Raw Normal View History

2022-08-23 15:32:55 +00:00
-- check conversion of numbers to date/time --
2022-08-26 15:43:31 +00:00
SELECT toDate(toInt32(toDate32('1930-01-01', 'UTC')), 'UTC'),
toDate(toInt32(toDate32('2151-01-01', 'UTC')), 'UTC'),
toDate(toInt64(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC')), 'UTC'),
toDate(toInt64(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC')), 'UTC'),
toDate32(toInt32(toDate32('1900-01-01', 'UTC')) - 1, 'UTC'),
toDate32(toInt32(toDate32('2299-12-31', 'UTC')) + 1, 'UTC'),
2022-08-24 21:26:44 +00:00
toDateTime(toInt64(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC')), 'UTC'),
toDateTime(toInt64(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC')), 'UTC');
2022-08-23 14:13:39 +00:00
-- check conversion of extended range type to normal range type --
2022-08-26 15:43:31 +00:00
SELECT toDate(toDate32('1930-01-01', 'UTC'), 'UTC'),
toDate(toDate32('2151-01-01', 'UTC'), 'UTC');
2022-08-17 15:33:36 +00:00
SELECT toDate(toDateTime64('1930-01-01 12:12:12.12', 3, 'UTC'), 'UTC'),
2022-08-21 15:59:09 +00:00
toDate(toDateTime64('2151-01-01 12:12:12.12', 3, 'UTC'), 'UTC');
2022-08-17 15:33:36 +00:00
SELECT toDateTime(toDateTime64('1930-01-01 12:12:12.12', 3, 'UTC'), 'UTC'),
2022-08-21 15:59:09 +00:00
toDateTime(toDateTime64('2151-01-01 12:12:12.12', 3, 'UTC'), 'UTC');
2022-08-17 15:33:36 +00:00
SELECT toDateTime(toDate32('1930-01-01', 'UTC'), 'UTC'),
2022-08-21 15:59:09 +00:00
toDateTime(toDate32('2151-01-01', 'UTC'), 'UTC');
2022-08-17 15:33:36 +00:00
2022-08-21 15:59:09 +00:00
SELECT toDateTime(toDate('2141-01-01', 'UTC'), 'UTC');
2022-08-17 15:33:36 +00:00
2022-08-23 14:13:39 +00:00
-- test DateTimeTransforms --
2022-08-17 15:33:36 +00:00
SELECT 'toStartOfDay';
2022-08-23 15:32:55 +00:00
SELECT toStartOfDay(toDate('2141-01-01', 'UTC'), 'UTC'),
2022-08-21 15:59:09 +00:00
toStartOfDay(toDate32('1930-01-01', 'UTC'), 'UTC'),
2022-08-17 15:33:36 +00:00
toStartOfDay(toDate32('2141-01-01', 'UTC'), 'UTC'),
2022-08-21 15:59:09 +00:00
toStartOfDay(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC'), 'UTC'),
2022-08-17 15:33:36 +00:00
toStartOfDay(toDateTime64('2141-01-01 12:12:12.123', 3, 'UTC'), 'UTC');
2022-08-23 14:13:39 +00:00
SELECT 'toStartOfWeek';
2022-08-26 15:43:31 +00:00
SELECT toStartOfWeek(toDate('1970-01-01', 'UTC')),
toStartOfWeek(toDate32('1970-01-01', 'UTC')),
toStartOfWeek(toDateTime('1970-01-01 10:10:10', 'UTC'), 0, 'UTC'),
toStartOfWeek(toDateTime64('1970-01-01 10:10:10.123', 3, 'UTC'), 1, 'UTC'),
toStartOfWeek(toDate32('1930-01-01', 'UTC')),
toStartOfWeek(toDate32('2151-01-01', 'UTC')),
toStartOfWeek(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC'), 2, 'UTC'),
toStartOfWeek(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC'), 3, 'UTC');
2022-08-23 14:13:39 +00:00
2022-08-17 15:33:36 +00:00
SELECT 'toMonday';
2022-08-26 15:43:31 +00:00
SELECT toMonday(toDate('1970-01-02', 'UTC')),
2022-08-23 14:13:39 +00:00
toMonday(toDate32('1930-01-01', 'UTC')),
2022-08-21 15:59:09 +00:00
toMonday(toDate32('2151-01-01', 'UTC')),
toMonday(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC'), 'UTC'),
2022-08-17 15:33:36 +00:00
toMonday(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC'), 'UTC');
SELECT 'toStartOfMonth';
2022-08-21 15:59:09 +00:00
SELECT toStartOfMonth(toDate32('1930-01-01', 'UTC')),
toStartOfMonth(toDate32('2151-01-01', 'UTC')),
toStartOfMonth(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC'), 'UTC'),
2022-08-17 15:33:36 +00:00
toStartOfMonth(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC'), 'UTC');
2022-08-23 14:13:39 +00:00
2022-08-17 15:33:36 +00:00
SELECT 'toLastDayOfMonth';
2022-08-26 15:43:31 +00:00
SELECT toLastDayOfMonth(toDate('2149-06-03', 'UTC')),
2022-08-23 14:13:39 +00:00
toLastDayOfMonth(toDate32('1930-01-01', 'UTC')),
2022-08-21 15:59:09 +00:00
toLastDayOfMonth(toDate32('2151-01-01', 'UTC')),
toLastDayOfMonth(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC'), 'UTC'),
2022-08-17 15:33:36 +00:00
toLastDayOfMonth(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC'), 'UTC');
SELECT 'toStartOfQuarter';
2022-08-21 15:59:09 +00:00
SELECT toStartOfQuarter(toDate32('1930-01-01', 'UTC')),
toStartOfQuarter(toDate32('2151-01-01', 'UTC')),
toStartOfQuarter(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC'), 'UTC'),
2022-08-17 15:33:36 +00:00
toStartOfQuarter(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC'), 'UTC');
SELECT 'toStartOfYear';
2022-08-21 15:59:09 +00:00
SELECT toStartOfYear(toDate32('1930-01-01', 'UTC')),
toStartOfYear(toDate32('2151-01-01', 'UTC')),
toStartOfYear(toDateTime64('1930-01-01 12:12:12.123', 3, 'UTC'), 'UTC'),
2022-08-23 14:15:20 +00:00
toStartOfYear(toDateTime64('2151-01-01 12:12:12.123', 3, 'UTC'), 'UTC');