Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-5895

Bad results when casting DATE_ADD(..) to some numeric types

    XMLWordPrintable

    Details

      Description

      This query

      SELECT CAST(DATE_ADD(101, INTERVAL 1 hour_second) AS SIGNED) AS c1, CAST(DATE_ADD(101, INTERVAL 1 hour_second) AS DOUBLE) AS c2,  CAST(DATE_ADD(101, INTERVAL 1 hour_second) AS DECIMAL(20)) AS c3;

      returns:

      +------+----------------+----------------+
      | c1   | c2             | c3             |
      +------+----------------+----------------+
      | 2000 | 20000101000001 | 20000101000001 |
      +------+----------------+----------------+
       

      The result must be the same for all three expressions.
      The question is: which is correct?

      The return value for "DATE_ADD(101, INTERVAL 1 hour_second)"
      is '2000-01-01 00:00:01'. But the data type in this context is VARCHAR
      (note VARCHAR is correct, as the argument is not a temporal data type!).
      So it should probably return 2000 in all three cases, i.e. parse
      the returned value as a string, without trying to treat it as a datetime.

        Attachments

          Activity

            People

            Assignee:
            bar Alexander Barkov
            Reporter:
            bar Alexander Barkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: