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

TO_DATE: Missing space in view frm, unexpected syntax error in a corner case

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Fixed
    • N/A
    • 12.3.1
    • Views
    • None
    • Not for Release Notes

    Description

      When TO_DATE function with DEFAULT clause is used in a view definition, the resulting frm is missing a space between the first argument and the DEFAULT word.

      bb-12.3-MDEV-19683-to_date 2b105f686c9b801d63cf9041093b9e2d24e0ae55

      TYPE=VIEW
      query=select to_date(`test`.`t`.`a`DEFAULT \'2020-01-01\' ON CONVERSION ERROR,\'YYYY-MM-DD\') AS `x` from `test`.`t`
      

      Normally it doesn't cause a problem, as the column names or text literals are quoted, but in certain cases, e.g. if the argument is NULL or a numeric constant, it leads to further syntax errors:

      CREATE OR REPLACE VIEW v AS SELECT TO_DATE(NULL DEFAULT '2020-01-01' ON CONVERSION ERROR, 'YYYY-MM-DD') AS x FROM t;
      ...
      TYPE=VIEW
      query=select to_date(NULLDEFAULT \'2020-01-01\' ON CONVERSION ERROR,\'YYYY-MM-DD\') AS `x` from `test`.`t`
      ...
      SELECT * FROM v' failed: ER_PARSE_ERROR (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''2020-01-01' ON CONVERSION ERROR,'YYYY-MM-DD') AS `x` from `test`.`t`
      

      CREATE TABLE t (a INT);
      CREATE VIEW v AS SELECT TO_DATE(a DEFAULT '2020-01-01' ON CONVERSION ERROR, 'YYYY-MM-DD') AS x FROM t;
      --cat_file $MARIADB_DATADIR/test/v.frm
       
      CREATE OR REPLACE VIEW v AS SELECT TO_DATE(NULL DEFAULT '2020-01-01' ON CONVERSION ERROR, 'YYYY-MM-DD') AS x FROM t;
      --cat_file $MARIADB_DATADIR/test/v.frm
      SELECT * FROM v;
       
      DROP VIEW v;
      DROP TABLE t;
      

      Attachments

        Issue Links

          Activity

            People

              monty Michael Widenius
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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