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

TO_DATE: Inconsistent treatment of different separators in the date and format strings

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Trivial
    • Resolution: Unresolved
    • N/A
    • 12.3
    • Server
    • None

    Description

      Both Oracle and MariaDB allow some leeway in the use of different separators between data string/format elements. Oracle behavior isn't very consistent, so I don't think MariaDB should strive to be compatible for each specific case. However, there are cases when the MariaDB behavior is incompatible with Oracle and looks illogical in general.

      For example, an extra dash in the format string is allowed:

      bb-12.3-MDEV-19683-to_date d5fb3dccd72d816c7181a069b91eedb3c76b2715

      MariaDB [test]> SELECT TO_DATE('2002 AD', 'YYYY - AD') FROM DUAL;
      +---------------------------------+
      | TO_DATE('2002 AD', 'YYYY - AD') |
      +---------------------------------+
      | 2002-02-09 00:00:00             |
      +---------------------------------+
      1 row in set (0.001 sec)
      

      but in the date string it is not:

      MariaDB [test]> SELECT TO_DATE('2002 - AD', 'YYYY AD') FROM DUAL;
      +---------------------------------+
      | TO_DATE('2002 - AD', 'YYYY AD') |
      +---------------------------------+
      | NULL                            |
      +---------------------------------+
       
      MariaDB [test]> show warnings;
      +---------+------+------------------------------------------------------------+
      | Level   | Code | Message                                                    |
      +---------+------+------------------------------------------------------------+
      | Warning | 1411 | Incorrect datetime value: '2002 - AD' for function to_date |
      +---------+------+------------------------------------------------------------+
      

      There is no problem with dash as such, or with the date string being longer than the format string, because this also works:

      MariaDB [test]> SELECT TO_DATE('2002 - AD', 'YYYY-AD') FROM DUAL;
      +---------------------------------+
      | TO_DATE('2002 - AD', 'YYYY-AD') |
      +---------------------------------+
      | 2002-02-09 00:00:00             |
      +---------------------------------+
      

      So the warning must be caused by the date string having a dash while the format string doesn't.

      In Oracle, all three work (I think – need to re-check, the fiddle is broken again)

      Attachments

        Issue Links

          Activity

            People

              elenst Elena Stepanova
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.