Files
greptimedb/tests/cases/standalone/common/system/timezone.result
dennis zhuang aafb468547 fix: set local or session time_zone not work (#4064)
* fix: set local or session time_zone not work

* chore: supports PostgreSQL-specific setting time zone
2024-05-29 00:06:13 +00:00

304 lines
7.5 KiB
Plaintext

--- tests for timezone ---
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| UTC |
+-----------+
SHOW VARIABLES system_time_zone;
+------------------+
| SYSTEM_TIME_ZONE |
+------------------+
| UTC |
+------------------+
select timezone();
+------------+
| timezone() |
+------------+
| UTC |
+------------+
CREATE TABLE test(d double, ts timestamp_ms time index);
Affected Rows: 0
INSERT INTO test values
(1, '2024-01-01 00:00:00'),
(2, '2024-01-02 08:00:00'),
(3, '2024-01-03 16:00:00'),
(4, '2024-01-04 00:00:00'),
(5, '2024-01-05 00:00:00+08:00');
Affected Rows: 5
SELECT * from test;
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts >= '2024-01-02 08:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts <= '2024-01-03 16:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
+-----+---------------------+
select date_format(ts, '%Y-%m-%d %H:%M:%S:%3f') from test;
+----------------------------------------------------+
| date_format(test.ts,Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
+----------------------------------------------------+
| 2024-01-01 00:00:00:000 |
| 2024-01-02 08:00:00:000 |
| 2024-01-03 16:00:00:000 |
| 2024-01-04 00:00:00:000 |
| 2024-01-04 16:00:00:000 |
+----------------------------------------------------+
select to_unixtime('2024-01-02 00:00:00');
+------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00")) |
+------------------------------------------+
| 1704153600 |
+------------------------------------------+
select to_unixtime('2024-01-02T00:00:00+08:00');
+------------------------------------------------+
| to_unixtime(Utf8("2024-01-02T00:00:00+08:00")) |
+------------------------------------------------+
| 1704124800 |
+------------------------------------------------+
--- UTC+8 ---
SET TIME_ZONE = '+8:00';
Affected Rows: 0
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| +08:00 |
+-----------+
SHOW VARIABLES system_time_zone;
+------------------+
| SYSTEM_TIME_ZONE |
+------------------+
| UTC |
+------------------+
select timezone();
+------------+
| timezone() |
+------------+
| +08:00 |
+------------+
SELECT * from test;
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts >= '2024-01-02 08:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts <= '2024-01-03 16:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
+-----+---------------------+
select date_format(ts, '%Y-%m-%d %H:%M:%S:%3f') from test;
+----------------------------------------------------+
| date_format(test.ts,Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
+----------------------------------------------------+
| 2024-01-01 08:00:00:000 |
| 2024-01-02 16:00:00:000 |
| 2024-01-04 00:00:00:000 |
| 2024-01-04 08:00:00:000 |
| 2024-01-05 00:00:00:000 |
+----------------------------------------------------+
select to_unixtime('2024-01-02 00:00:00');
+------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00")) |
+------------------------------------------+
| 1704124800 |
+------------------------------------------+
select to_unixtime('2024-01-02 00:00:00+08:00');
+------------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00+08:00")) |
+------------------------------------------------+
| 1704124800 |
+------------------------------------------------+
--- UTC-8 ---
SET SESSION TIME_ZONE = '-8:00';
Affected Rows: 0
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| -08:00 |
+-----------+
SHOW VARIABLES system_time_zone;
+------------------+
| SYSTEM_TIME_ZONE |
+------------------+
| UTC |
+------------------+
select timezone();
+------------+
| timezone() |
+------------+
| -08:00 |
+------------+
SELECT * from test;
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts >= '2024-01-02 08:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
| 5.0 | 2024-01-04T16:00:00 |
+-----+---------------------+
SELECT * from test where ts <= '2024-01-03 16:00:00';
+-----+---------------------+
| d | ts |
+-----+---------------------+
| 1.0 | 2024-01-01T00:00:00 |
| 2.0 | 2024-01-02T08:00:00 |
| 3.0 | 2024-01-03T16:00:00 |
| 4.0 | 2024-01-04T00:00:00 |
+-----+---------------------+
select date_format(ts, '%Y-%m-%d %H:%M:%S:%3f') from test;
+----------------------------------------------------+
| date_format(test.ts,Utf8("%Y-%m-%d %H:%M:%S:%3f")) |
+----------------------------------------------------+
| 2023-12-31 16:00:00:000 |
| 2024-01-02 00:00:00:000 |
| 2024-01-03 08:00:00:000 |
| 2024-01-03 16:00:00:000 |
| 2024-01-04 08:00:00:000 |
+----------------------------------------------------+
select to_unixtime('2024-01-02 00:00:00');
+------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00")) |
+------------------------------------------+
| 1704182400 |
+------------------------------------------+
select to_unixtime('2024-01-02 00:00:00+08:00');
+------------------------------------------------+
| to_unixtime(Utf8("2024-01-02 00:00:00+08:00")) |
+------------------------------------------------+
| 1704124800 |
+------------------------------------------------+
drop table test;
Affected Rows: 0
-- revert timezone to UTC
SET LOCAL TIME_ZONE = 'UTC';
Affected Rows: 0
SHOW VARIABLES time_zone;
+-----------+
| TIME_ZONE |
+-----------+
| UTC |
+-----------+
select timezone();
+------------+
| timezone() |
+------------+
| UTC |
+------------+