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

When you have a COMMENT and a CHECK on a column, the SHOW CREATE TABLE creates an invalid query

    XMLWordPrintable

Details

    Description

      When you create a table that has a column with both a CHECK and a COMMENT (or alter a table to add such a column), then the SHOW CREATE TABLE statement provides the two attributes in the wrong order, causing a syntax error.

      Please see the test script for examples.

      SELECT VERSION();
       
      # Initial SQL for Create Table
      CREATE TABLE `testTableWithComment`(
        `i` INT NOT NULL COMMENT 'A comment!' CHECK (`i` > 5),
        PRIMARY KEY (`i`)
      ) ENGINE=INNODB;
       
      # Get the Create Table SQL
      SHOW CREATE TABLE `testTableWithComment`;
      /*
      CREATE TABLE `testTableWithComment` (
        `i` int(11) NOT NULL CHECK (`i` > 5) COMMENT 'A comment!',
        PRIMARY KEY (`i`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1
      */
       
      /* When the above is run, you get:
      Error Code: 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 'COMMENT 'A comment!',
        PRIMARY KEY (`i`)
      ) ENGINE=InnoDB DEFAULT CHARSET=lati' at line 10
      */
       
      # Altering Table
      ALTER TABLE `testTableWithComment`
        ADD COLUMN `q` INT NOT NULL COMMENT 'A boring comment' CHECK (`q` > 2);
        
      # Get the Create Table SQL
      SHOW CREATE TABLE `testTableWithComment`;
      /* Same issue with the new column:
      CREATE TABLE `testTableWithComment` (
        `i` int(11) NOT NULL CHECK (`i` > 5) COMMENT 'A comment!',
        `q` int(11) NOT NULL CHECK (`q` > 2) COMMENT 'A boring comment',
        PRIMARY KEY (`i`)
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1*/
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rmhumphries Robert Humphries
              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.