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

STR_TO_DATE does not return NULL for invalid dates

    XMLWordPrintable

Details

    Description

      MariaDB 10.1

      MariaDB [test]> SELECT STR_TO_DATE('1949-02-30','%Y-%m-%d');
      +--------------------------------------+
      | STR_TO_DATE('1949-02-30','%Y-%m-%d') |
      +--------------------------------------+
      | 1949-02-30                           |
      +--------------------------------------+
      1 row in set (0.00 sec)
      

      According to specification, it should be NULL for invalid date values.
      Reproducible with MySQL 5.5/5.6, but fixed in MySQL 5.7 (only it produces duplicate warnings, let's not do it):

      MySQL 5.7

      MySQL [test]> SELECT STR_TO_DATE('1949-02-30','%Y,%m,%d');
      +--------------------------------------+
      | STR_TO_DATE('1949-02-30','%Y,%m,%d') |
      +--------------------------------------+
      | NULL                                 |
      +--------------------------------------+
      1 row in set, 2 warnings (0.00 sec)
       
      MySQL [test]> show warnings;
      +---------+------+-----------------------------------------------------------------+
      | Level   | Code | Message                                                         |
      +---------+------+-----------------------------------------------------------------+
      | Warning | 1411 | Incorrect datetime value: '1949-02-30' for function str_to_date |
      | Warning | 1411 | Incorrect datetime value: '1949-02-30' for function str_to_date |
      +---------+------+-----------------------------------------------------------------+
      2 rows in set (0.00 sec)
      

      Found on stackoverflow.

      Attachments

        Activity

          People

            bar Alexander Barkov
            elenst Elena Stepanova
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.