[MDEV-27000] TIMESTAMP '<date>' returns ER_WRONG_VALUE (Incorrect DATETIME value) Created: 2021-11-08  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7
Fix Version/s: 10.4, 10.5, 10.6

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: upstream


 Description   

On some reason, the following returns an error:

10.2

MariaDB [test]> select timestamp '2021-12-12';
ERROR 1525 (HY000): Incorrect DATETIME value: '2021-12-12'
MariaDB [test]> select timestamp '20211212';
ERROR 1525 (HY000): Incorrect DATETIME value: '20211212'

while this, for example, works:

MariaDB [test]> select timestamp '2021-12-12 0';
+--------------------------+
| timestamp '2021-12-12 0' |
+--------------------------+
| 2021-12-12 00:00:00      |
+--------------------------+
1 row in set (0.000 sec)

This also works

MariaDB [test]> select cast('2021-12-12' as datetime);
+--------------------------------+
| cast('2021-12-12' as datetime) |
+--------------------------------+
| 2021-12-12 00:00:00            |
+--------------------------------+
1 row in set (0.000 sec)

and naturally a date can be inserted into a timestamp/datetime column.

bar said the error upon timestamp literal may be a bug, so I'm filing it so that it's at least tracked.

I cannot find a definitive proof in documentation whether it should work or not. MySQL manual, while quite verbose, doesn't say explicitly whether it should work. It has, however, this note:

Values specified as numbers should be 6, 8, 12, or 14 digits long. If a number is 8 or 14 digits long, it is assumed to be in YYYYMMDD or YYYYMMDDhhmmss format and that the year is given by the first 4 digits

So, it appears that at least timestamp '20211212' should work (but it doesn't work in MySQL either).

MariaDB documentation is very confusing, it doesn't help at all.

One non-obvious effect is that in 10.7, --as-of option added to mysqldump in the scope of MDEV-16355 doesn't work with date-only values. It happens because the value is converted into a statement like

SELECT * FROM <table> FOR SYSTEM_TIME AS OF TIMESTAMP '<value>';


Generated at Thu Feb 08 09:49:34 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.