I agree there is inconsistency here, even though maybe it's not an intuitive one.
Let's take for example MINUTE_SECOND vs MINUTE_MICROSECOND (it's the same for DAY_MICROSECOND, but shorter).
The format of the interval values described both for MariaDB and MySQL as
MINUTE_MICROSECOND 'MINUTES:SECONDS.MICROSECONDS'
|
MINUTE_SECOND 'MINUTES:SECONDS'
|
The punctuation character between integers can be anything.
So, it's not a floating point between seconds and microseconds, it's just a separator between an integer number of seconds and integer number of microseconds. Same for a separator between minutes and seconds.
And it does indeed work like that for minutes and seconds:
1.5 is not one minute and a half, it's 1 minute and 5 seconds
|
MariaDB [test]> select date_add('1000-01-01 00:00:00', interval '01.5' minute_second);
|
+----------------------------------------------------------------+
|
| date_add('1000-01-01 00:00:00', interval '01.5' minute_second) |
|
+----------------------------------------------------------------+
|
| 1000-01-01 00:01:05 |
|
+----------------------------------------------------------------+
|
1 row in set (0.00 sec)
|
1.50 is not the same as 1.5, it's 1 minute and 50 seconds
|
MariaDB [test]> select date_add('1000-01-01 00:00:00', interval '01.50' minute_second);
|
+-----------------------------------------------------------------+
|
| date_add('1000-01-01 00:00:00', interval '01.50' minute_second) |
|
+-----------------------------------------------------------------+
|
| 1000-01-01 00:01:50 |
|
+-----------------------------------------------------------------+
|
1 row in set (0.00 sec)
|
1.5000000 is not the same as 1.5, it's 1 minute and 5000000 seconds
|
MariaDB [test]> select date_add('1000-01-01 00:00:00', interval '01.5000000' minute_second);
|
+----------------------------------------------------------------------+
|
| date_add('1000-01-01 00:00:00', interval '01.5000000' minute_second) |
|
+----------------------------------------------------------------------+
|
| 1000-02-27 20:54:20 |
|
+----------------------------------------------------------------------+
|
1 row in set (0.00 sec)
|
Same exact thing happens with microseconds when they grow above 6 digits
01.01.5000000 is 1 minute, 1 second and 5000000 microseconds == 1 minute and 6 seconds
|
MariaDB [test]> select date_add('1000-01-01 00:00:00', interval '01.01.5000000' minute_microsecond);
|
+------------------------------------------------------------------------------+
|
| date_add('1000-01-01 00:00:00', interval '01.01.5000000' minute_microsecond) |
|
+------------------------------------------------------------------------------+
|
| 1000-01-01 00:01:06.000000 |
|
+------------------------------------------------------------------------------+
|
1 row in set (0.00 sec)
|
PROBLEM
Thus, it's reasonable to expect – from the definition and by analogy – that 01.01.5 MINUTE_MICROSECOND would be 1 minute, 1 second and 5 microseconds; but it's not so:
MariaDB [test]> select date_add('1000-01-01 00:00:00', interval '01.01.5' minute_microsecond);
|
+------------------------------------------------------------------------+
|
| date_add('1000-01-01 00:00:00', interval '01.01.5' minute_microsecond) |
|
+------------------------------------------------------------------------+
|
| 1000-01-01 00:01:01.500000 |
|
+------------------------------------------------------------------------+
|
1 row in set (0.00 sec)
|
I don't know whether it needs to be fixed, or the specification needs to be refined, leaving it to serg to decide.
Detected using JOOQ, which generates SQL with nanosecond precision for subsecond part. Reported here: https://github.com/jOOQ/jOOQ/issues/6820