Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TIMESTAMP with explicit time zone #51742

Open
mjonss opened this issue Mar 13, 2024 · 8 comments
Open

Support TIMESTAMP with explicit time zone #51742

mjonss opened this issue Mar 13, 2024 · 8 comments
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) type/compatibility type/enhancement The issue or PR belongs to an enhancement.

Comments

@mjonss
Copy link
Contributor

mjonss commented Mar 13, 2024

Enhancement

In MySQL 8.0.19, the timestamp (or really datetime) literal support explicit time zone, like TIMESTAMP'2024-03-13 11:33:44+01:00'
see https://dev.mysql.com/doc/refman/8.0/en/date-and-time-literals.html

So the suggestion is to allow the "[+-][0-9][0-9]:[0-9][0-9]" syntax for the TIMESTAMP literal, and handling it without any other time zone conversions, apart from adjusting the time accordingly to the given time zone offset.

The reason is to give developers a more straight forward way of inserting timestamps and datetimes without having to change the @@time_zone variable or be affected by internal time zone handling when inserting or querying data.

@mjonss mjonss added the type/enhancement The issue or PR belongs to an enhancement. label Mar 13, 2024
@dveeden dveeden added type/compatibility compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) labels Mar 15, 2024
@dveeden dveeden mentioned this issue Mar 18, 2024
69 tasks
@dveeden
Copy link
Contributor

dveeden commented Mar 26, 2024

Please include CAST(...AT TIME ZONE...) as part of this.

@dveeden
Copy link
Contributor

dveeden commented Aug 20, 2024

Another small incompatibility related to this:

mysql-9.0.1> SELECT TIMESTAMP '2024-01-01 18';
+---------------------------+
| TIMESTAMP '2024-01-01 18' |
+---------------------------+
| 2024-01-01 18:00:00       |
+---------------------------+
1 row in set (0.00 sec)

mysql-9.0.1> SELECT TIMESTAMP '2024-01-01 18:00';
+------------------------------+
| TIMESTAMP '2024-01-01 18:00' |
+------------------------------+
| 2024-01-01 18:00:00          |
+------------------------------+
1 row in set (0.00 sec)

mysql-9.0.1> SELECT TIMESTAMP '2024-01-01 18:00:00';
+---------------------------------+
| TIMESTAMP '2024-01-01 18:00:00' |
+---------------------------------+
| 2024-01-01 18:00:00             |
+---------------------------------+
1 row in set (0.00 sec)
tidb> SELECT TIMESTAMP '2024-01-01 18';
ERROR 1292 (22007): Incorrect datetime value: '2024-01-01 18'
tidb> SELECT TIMESTAMP '2024-01-01 18:00';
ERROR 1292 (22007): Incorrect datetime value: '2024-01-01 18:00'
tidb> SELECT TIMESTAMP '2024-01-01 18:00:00';
+---------------------------------+
| TIMESTAMP '2024-01-01 18:00:00' |
+---------------------------------+
| 2024-01-01 18:00:00             |
+---------------------------------+
1 row in set (0.00 sec)

@dveeden
Copy link
Contributor

dveeden commented Aug 20, 2024

And for ODBC-style it looks like MySQL is extremely lax with validation, but TiDB isn't.

mysql-9.0.1> SELECT { ts '2024-01' };
+---------+
| 2024-01 |
+---------+
| 2024-01 |
+---------+
1 row in set (0.00 sec)
tidb> SELECT { ts '2024-01' };
ERROR 1292 (22007): Incorrect datetime value: '2024-01'

@dveeden
Copy link
Contributor

dveeden commented Aug 20, 2024

And TiDB doesn't raise a warning where MySQL does:

mysql-9.0.1> SELECT DATE'2012@12@31';
+------------------+
| DATE'2012@12@31' |
+------------------+
| 2012-12-31       |
+------------------+
1 row in set, 1 warning (0.00 sec)

mysql-9.0.1> SHOW WARNINGS;
+---------+------+-------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                     |
+---------+------+-------------------------------------------------------------------------------------------------------------+
| Warning | 4095 | Delimiter '@' in position 4 in datetime value '2012@12@31' at row 1 is deprecated. Prefer the standard '-'. |
+---------+------+-------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
tidb> SELECT DATE'2012@12@31';
+------------------+
| DATE'2012@12@31' |
+------------------+
| 2012-12-31       |
+------------------+
1 row in set (0.00 sec)

@dveeden
Copy link
Contributor

dveeden commented Aug 20, 2024

For some cases the error number and message are different:

mysql-9.0.1> SELECT TIME '101112';
+---------------+
| TIME '101112' |
+---------------+
| 10:11:12      |
+---------------+
1 row in set (0.00 sec)

mysql-9.0.1> SELECT TIME '109112';
ERROR 1525 (HY000): Incorrect TIME value: '109112'
tidb> SELECT TIME '101112';
+---------------+
| TIME '101112' |
+---------------+
| 10:11:12      |
+---------------+
1 row in set (0.01 sec)

tidb> SELECT TIME '109112';
ERROR 1292 (22007): Truncated incorrect time value: '109112'

@dveeden
Copy link
Contributor

dveeden commented Aug 20, 2024

And example for a timestamp literal with a timezone offset:

mysql-9.0.1> SELECT TIMESTAMP '2024-08-07 10:11:12-01:23';
+---------------------------------------+
| TIMESTAMP '2024-08-07 10:11:12-01:23' |
+---------------------------------------+
| 2024-08-07 13:34:12                   |
+---------------------------------------+
1 row in set (0.00 sec)

@dveeden
Copy link
Contributor

dveeden commented Aug 20, 2024

Note that the range of offset should be a bit stricter than what's in the description of this issue.

mysql-9.0.1> SELECT TIMESTAMP '2024-08-07 10:11:12-14:00';
+---------------------------------------+
| TIMESTAMP '2024-08-07 10:11:12-14:00' |
+---------------------------------------+
| 2024-08-08 02:11:12                   |
+---------------------------------------+
1 row in set (0.00 sec)

mysql-9.0.1> SELECT TIMESTAMP '2024-08-07 10:11:12-15:00';
ERROR 1525 (HY000): Incorrect DATETIME value: '2024-08-07 10:11:12-15:00'

@dveeden
Copy link
Contributor

dveeden commented Aug 20, 2024

So what I think is needed:

  • Support timezone offset for literals
  • Correct errors to match those of MySQL
  • Add warnings for deprecated delimiters
  • Relax what ODBC compatible syntax we support
  • Relax timestamp parsing for timestamps with only ... HH or ... HH:MM
  • Support CAST(...AT TIME ZONE...AS DATETIME)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) type/compatibility type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants