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

INSERT INTO td SELECT now() WHERE 1=1 Works in 10.1, Fails in 10.2 and 10.3

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.2.17, 10.3.8
    • N/A
    • Parser
    • None

    Description

      Queries of the following type (auto-generated) work in MariaDB 10.1.33, but fail in 10.2.17 and 10.3.8:

      INSERT INTO td SELECT now() WHERE 1=1;
      

      It is common for the code to auto add the "WHERE 0=1" or "WHERE 1=1".

      10.1:

      mysql> CREATE TABLE `td` (
          -> `t` datetime DEFAULT NULL
          -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs;
      Query OK, 0 rows affected (1.87 sec)
       
      mysql> insert into td select now() where 1=1;
      Query OK, 1 row affected (0.02 sec)
      Records: 1  Duplicates: 0  Warnings: 0
       
      mysql> select * from td;
      +---------------------+
      | t                   |
      +---------------------+
      | 2018-08-14 16:59:44 |
      +---------------------+
      1 row in set (0.00 sec)
      

      In both 10.2 and 10.3, we see:

      mysql> CREATE TABLE `td` (
          -> `t` datetime DEFAULT NULL
          -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs;
      Query OK, 0 rows affected (1.67 sec)
       
      mysql> insert into td select now() where 1=1;
      ERROR 1064 (42000): 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 'where 1=1' at line 1
      

      One strange thing about 10.1 is that the sub-query ("select now() where 1=1;") fails when issued by itself, but works when it is part of the INSERT INTO:

      mysql> select now() where 1=1;
      ERROR 1064 (42000): 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 'where 1=1' at line 1
      

      Attachments

        Activity

          People

            bar Alexander Barkov
            ccalender Chris Calender (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 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.