Skip to content

Format create table sql error when encounter unique key with comment #538

Description

@honganan
CREATE TABLE `g_platform_payway` (
	`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id', 
	`platform_code` varchar(45) NOT NULL, 
	`pay_way` varchar(32) NOT NULL, 
	PRIMARY KEY (`id`), 
	UNIQUE `uniq_playform_payway` USING BTREE (`platform_code`, `pay_way`) COMMENT 'should be unique'
) ENGINE = InnoDB CHARSET = utf8 COMMENT = 'config table'

when using the following code to format this above sql, error occured:

Statement statement = CCJSqlParserUtil.parse(sql3);

the error likes:

Exception in thread "main" net.sf.jsqlparser.JSQLParserException
	at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:54)
	at com.greenline.hati.biz.manager.common.SqlUtil.main(SqlUtil.java:118)
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered " "USING" "USING "" at line 11, column 65.
Was expecting one of:
    "," ...
    ")" ...
    
	at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:15112)
	at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:14968)
	at net.sf.jsqlparser.parser.CCJSqlParser.CreateTable(CCJSqlParser.java:8232)

when I removed the USING BTREE COMMENT 'should be unique', the problem disappeared.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions