mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-07 13:52:59 +00:00
* feat remove datetime type * chore: fix unit test * chore: add column test * refactor: move create and alter validation to one place * chore: minor refactor ut * refactor: rename expr_factory to expr_helper * chore: remove unnecessary args
225 lines
14 KiB
Plaintext
225 lines
14 KiB
Plaintext
--- date_add ---
|
|
SELECT date_add('2023-12-06 07:39:46.222'::TIMESTAMP_MS, INTERVAL '5 day');
|
|
|
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| date_add(arrow_cast(Utf8("2023-12-06 07:39:46.222"),Utf8("Timestamp(Millisecond, None)")),IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 5, nanoseconds: 0 }")) |
|
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-12-11T07:39:46.222 |
|
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_add('2023-12-06 07:39:46.222'::TIMESTAMP_MS, '5 day');
|
|
|
|
+----------------------------------------------------------------------------------------------------------+
|
|
| date_add(arrow_cast(Utf8("2023-12-06 07:39:46.222"),Utf8("Timestamp(Millisecond, None)")),Utf8("5 day")) |
|
|
+----------------------------------------------------------------------------------------------------------+
|
|
| 2023-12-11T07:39:46.222 |
|
|
+----------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_add('2023-12-06'::DATE, INTERVAL '3 month 5 day');
|
|
|
|
+------------------------------------------------------------------------------------------------------------------+
|
|
| date_add(Utf8("2023-12-06"),IntervalMonthDayNano("IntervalMonthDayNano { months: 3, days: 5, nanoseconds: 0 }")) |
|
|
+------------------------------------------------------------------------------------------------------------------+
|
|
| 2024-03-11 |
|
|
+------------------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_add('2023-12-06'::DATE, '3 month 5 day');
|
|
|
|
+----------------------------------------------------+
|
|
| date_add(Utf8("2023-12-06"),Utf8("3 month 5 day")) |
|
|
+----------------------------------------------------+
|
|
| 2024-03-11 |
|
|
+----------------------------------------------------+
|
|
|
|
--- date_sub ---
|
|
SELECT date_sub('2023-12-06 07:39:46.222'::TIMESTAMP_MS, INTERVAL '5 day');
|
|
|
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| date_sub(arrow_cast(Utf8("2023-12-06 07:39:46.222"),Utf8("Timestamp(Millisecond, None)")),IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 5, nanoseconds: 0 }")) |
|
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-12-01T07:39:46.222 |
|
|
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_sub('2023-12-06 07:39:46.222'::TIMESTAMP_MS, '5 day');
|
|
|
|
+----------------------------------------------------------------------------------------------------------+
|
|
| date_sub(arrow_cast(Utf8("2023-12-06 07:39:46.222"),Utf8("Timestamp(Millisecond, None)")),Utf8("5 day")) |
|
|
+----------------------------------------------------------------------------------------------------------+
|
|
| 2023-12-01T07:39:46.222 |
|
|
+----------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_sub('2023-12-06'::DATE, INTERVAL '3 month 5 day');
|
|
|
|
+------------------------------------------------------------------------------------------------------------------+
|
|
| date_sub(Utf8("2023-12-06"),IntervalMonthDayNano("IntervalMonthDayNano { months: 3, days: 5, nanoseconds: 0 }")) |
|
|
+------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-09-01 |
|
|
+------------------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_sub('2023-12-06'::DATE, '3 month 5 day');
|
|
|
|
+----------------------------------------------------+
|
|
| date_sub(Utf8("2023-12-06"),Utf8("3 month 5 day")) |
|
|
+----------------------------------------------------+
|
|
| 2023-09-01 |
|
|
+----------------------------------------------------+
|
|
|
|
--- date_format ---
|
|
SELECT date_format('2023-12-06 07:39:46.222'::TIMESTAMP_MS, '%Y-%m-%d %H:%M:%S:%3f');
|
|
|
|
+-----------------------------------------------------------------------------------------------------------------------------+
|
|
| date_format(arrow_cast(Utf8("2023-12-06 07:39:46.222"),Utf8("Timestamp(Millisecond, None)")),Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
|
|
+-----------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-12-06 07:39:46:222 |
|
|
+-----------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_format('2023-12-06 07:39:46.222'::TIMESTAMP_S, '%Y-%m-%d %H:%M:%S:%3f');
|
|
|
|
+------------------------------------------------------------------------------------------------------------------------+
|
|
| date_format(arrow_cast(Utf8("2023-12-06 07:39:46.222"),Utf8("Timestamp(Second, None)")),Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
|
|
+------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-12-06 07:39:46:000 |
|
|
+------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
--- datetime not supported yet ---
|
|
SELECT date_format('2023-12-06 07:39:46.222'::DATETIME, '%Y-%m-%d %H:%M:%S:%3f');
|
|
|
|
+-----------------------------------------------------------------------------------------------------------------------------+
|
|
| date_format(arrow_cast(Utf8("2023-12-06 07:39:46.222"),Utf8("Timestamp(Microsecond, None)")),Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
|
|
+-----------------------------------------------------------------------------------------------------------------------------+
|
|
| 2023-12-06 07:39:46:222 |
|
|
+-----------------------------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_format('2023-12-06'::DATE, '%m-%d');
|
|
|
|
+-----------------------------------------------+
|
|
| date_format(Utf8("2023-12-06"),Utf8("%m-%d")) |
|
|
+-----------------------------------------------+
|
|
| 12-06 |
|
|
+-----------------------------------------------+
|
|
|
|
--- test date functions with table rows ---
|
|
CREATE TABLE dates(d DATE, ts timestamp time index);
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO dates VALUES ('1992-01-01'::DATE, 1);
|
|
|
|
Affected Rows: 1
|
|
|
|
INSERT INTO dates VALUES ('1993-12-30'::DATE, 2);
|
|
|
|
Affected Rows: 1
|
|
|
|
INSERT INTO dates VALUES ('2023-12-06'::DATE, 3);
|
|
|
|
Affected Rows: 1
|
|
|
|
--- date_add ---
|
|
SELECT date_add(d, INTERVAL '1 year 2 month 3 day') from dates;
|
|
|
|
+--------------------------------------------------------------------------------------------------------+
|
|
| date_add(dates.d,IntervalMonthDayNano("IntervalMonthDayNano { months: 14, days: 3, nanoseconds: 0 }")) |
|
|
+--------------------------------------------------------------------------------------------------------+
|
|
| 1993-03-04 |
|
|
| 1995-03-03 |
|
|
| 2025-02-09 |
|
|
+--------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_add(d, '1 year 2 month 3 day') from dates;
|
|
|
|
+------------------------------------------------+
|
|
| date_add(dates.d,Utf8("1 year 2 month 3 day")) |
|
|
+------------------------------------------------+
|
|
| 1993-03-04 |
|
|
| 1995-03-03 |
|
|
| 2025-02-09 |
|
|
+------------------------------------------------+
|
|
|
|
SELECT date_add(ts, INTERVAL '1 year 2 month 3 day') from dates;
|
|
|
|
+---------------------------------------------------------------------------------------------------------+
|
|
| date_add(dates.ts,IntervalMonthDayNano("IntervalMonthDayNano { months: 14, days: 3, nanoseconds: 0 }")) |
|
|
+---------------------------------------------------------------------------------------------------------+
|
|
| 1971-03-04T00:00:00.001 |
|
|
| 1971-03-04T00:00:00.002 |
|
|
| 1971-03-04T00:00:00.003 |
|
|
+---------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_add(ts, '1 year 2 month 3 day') from dates;
|
|
|
|
+-------------------------------------------------+
|
|
| date_add(dates.ts,Utf8("1 year 2 month 3 day")) |
|
|
+-------------------------------------------------+
|
|
| 1971-03-04T00:00:00.001 |
|
|
| 1971-03-04T00:00:00.002 |
|
|
| 1971-03-04T00:00:00.003 |
|
|
+-------------------------------------------------+
|
|
|
|
--- date_sub ---
|
|
SELECT date_sub(d, INTERVAL '1 year 2 month 3 day') from dates;
|
|
|
|
+--------------------------------------------------------------------------------------------------------+
|
|
| date_sub(dates.d,IntervalMonthDayNano("IntervalMonthDayNano { months: 14, days: 3, nanoseconds: 0 }")) |
|
|
+--------------------------------------------------------------------------------------------------------+
|
|
| 1990-10-29 |
|
|
| 1992-10-27 |
|
|
| 2022-10-03 |
|
|
+--------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_sub(d, '1 year 2 month 3 day') from dates;
|
|
|
|
+------------------------------------------------+
|
|
| date_sub(dates.d,Utf8("1 year 2 month 3 day")) |
|
|
+------------------------------------------------+
|
|
| 1990-10-29 |
|
|
| 1992-10-27 |
|
|
| 2022-10-03 |
|
|
+------------------------------------------------+
|
|
|
|
SELECT date_sub(ts, INTERVAL '1 year 2 month 3 day') from dates;
|
|
|
|
+---------------------------------------------------------------------------------------------------------+
|
|
| date_sub(dates.ts,IntervalMonthDayNano("IntervalMonthDayNano { months: 14, days: 3, nanoseconds: 0 }")) |
|
|
+---------------------------------------------------------------------------------------------------------+
|
|
| 1968-10-29T00:00:00.001 |
|
|
| 1968-10-29T00:00:00.002 |
|
|
| 1968-10-29T00:00:00.003 |
|
|
+---------------------------------------------------------------------------------------------------------+
|
|
|
|
SELECT date_sub(ts, '1 year 2 month 3 day') from dates;
|
|
|
|
+-------------------------------------------------+
|
|
| date_sub(dates.ts,Utf8("1 year 2 month 3 day")) |
|
|
+-------------------------------------------------+
|
|
| 1968-10-29T00:00:00.001 |
|
|
| 1968-10-29T00:00:00.002 |
|
|
| 1968-10-29T00:00:00.003 |
|
|
+-------------------------------------------------+
|
|
|
|
--- date_format ---
|
|
SELECT date_format(d, '%Y-%m-%d %H:%M:%S:%3f') from dates;
|
|
|
|
+----------------------------------------------------+
|
|
| date_format(dates.d,Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
|
|
+----------------------------------------------------+
|
|
| 1992-01-01 00:00:00:000 |
|
|
| 1993-12-30 00:00:00:000 |
|
|
| 2023-12-06 00:00:00:000 |
|
|
+----------------------------------------------------+
|
|
|
|
SELECT date_format(ts, '%Y-%m-%d %H:%M:%S:%3f') from dates;
|
|
|
|
+-----------------------------------------------------+
|
|
| date_format(dates.ts,Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
|
|
+-----------------------------------------------------+
|
|
| 1970-01-01 00:00:00:001 |
|
|
| 1970-01-01 00:00:00:002 |
|
|
| 1970-01-01 00:00:00:003 |
|
|
+-----------------------------------------------------+
|
|
|
|
DROP TABLE dates;
|
|
|
|
Affected Rows: 0
|
|
|