[MDEV-20397] Support TIMESTAMP, DATETIME, TIME in ROUND() and TRUNCATE() Created: 2019-08-21  Updated: 2023-07-19  Resolved: 2019-08-22

Status: Closed
Project: MariaDB Server
Component/s: Data types, Temporal Types
Fix Version/s: 10.4.8

Type: Task Priority: Critical
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-18153 Assertion `0' or Assertion `btr_valid... Closed
Relates
relates to MDEV-23032 FLOOR()/CEIL() incorrectly calculate ... Closed
relates to MDEV-23311 CEILING() and FLOOR() convert tempora... Closed

 Description   

As of versions 10.3.x and 10.4.7, functions ROUND() and TRUNCATE() convert temporal input to double and then return a rounded/truncated double value.

This behaviour is quite useless, because can return '60' at the end:

  • ROUND() in double format can return '60' at the end by definition
  • TRUNCATE() in double format can return '60' at the end because of lack of precision:

    TRUNCATE(TIMESTAMP'2001-12-31 23:59:59.999999', 1);
    

    +----------------------------------------------------+
    | TRUNCATE(TIMESTAMP'2001-12-31 23:59:59.999999', 1) |
    +----------------------------------------------------+
    |                                   20011231235960.0 |
    +----------------------------------------------------+
    

Therefore a rounded or truncated double value cannot be converted back to TIMESTAMP, DATETIME or TIME easily.

In order to fix MDEV-18153 easier, let's implement native TIMESTAMP, DATETIME, TIME support in ROUND() and TRUNCATE().

Let's change these functions to return:

  • TIME in case of a TIME input
  • DATETIME in case of a DATETIME input
  • DATETIME in case of a TIMESTAMP input

Note, ROUND(timestamp) will return DATETIME for now. It should be fine in 99% cases, but won't work well near DST changes. Let's implement real native TIMESTAMP support in ROUND() in a separate change later.

Note, the DATE data type is out of scope of this task. ROUND() and TRUNCATE() will still return a double result for a DATE input. Native DATE support for ROUND() and TRUNCATE() will be implemented separately, when needed.


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