[MDEV-19163] When you have a COMMENT and a CHECK on a column, the SHOW CREATE TABLE creates an invalid query Created: 2019-04-03  Updated: 2019-04-03  Resolved: 2019-04-03

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Data Definition - Create Table
Affects Version/s: 10.3.13
Fix Version/s: N/A

Type: Bug Priority: Minor
Reporter: Robert Humphries Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: show
Environment:

Windows 10 64bit


Issue Links:
Duplicate
is duplicated by MDEV-17654 Incorrect syntax returned for column ... Closed
is duplicated by MDEV-18473 DB restore fails when CHECK and COMME... Closed

 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*/



 Comments   
Comment by Elena Stepanova [ 2019-04-03 ]

Thanks for the report. This problem is being tracked in the scope of MDEV-17654.

Generated at Thu Feb 08 08:49:32 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.