Skip to content

Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "UNIQUE" "UNIQUE"  #1893

Open
@Meow-Cat

Description

@Meow-Cat

I tried using 3 versions: 4.5, 4.6, 4.7.
I want to get table name from this sql:

CREATE TABLE `sys_user`
( 
`id` bigint NOT NULL, 
`role_id` bigint NULL, 
`name` varchar (255) NULL, 
`age` int NULL, 
`remark` longtext NULL, 
`local` varchar (255) NULL, 
`address` varchar (255) NULL, 
PRIMARY KEY (`id`) , 
UNIQUE INDEX `ina_index` (`id`,`name`,`age`) USING BTREE COMMENT 'Unique index of id, name, age', 
INDEX (`local`) USING BTREE COMMENT 'Index of local', 
FOREIGN KEY (`role_id`) REFERENCES `sys_role` (`role_id`) 
) 

They all gave me the same error

Exception in thread "main" net.sf.jsqlparser.JSQLParserException: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "UNIQUE" "UNIQUE"
    at line 10, column 3.

Was expecting one of:

    "ACTION"
    "ACTIVE"
    "ALGORITHM"
    "ARCHIVE"
    "ARRAY"
    "AT"
    "BYTE"
    "CASCADE"

When I modify the sql

CREATE TABLE `sys_user`
( 
`id` bigint NOT NULL, 
`role_id` bigint NULL, 
`name` varchar (255) NULL, 
`age` int NULL, 
`remark` longtext NULL, 
`local` varchar (255) NULL, 
`address` varchar (255) NULL, 
PRIMARY KEY (`id`) , 
UNIQUE (`id`,`name`,`age`) USING BTREE COMMENT 'Unique index of id, name, age', 
INDEX (`local`) USING BTREE COMMENT 'Index of local', 
FOREIGN KEY (`role_id`) REFERENCES `sys_role` (`role_id`) 
) 

The execution was successful

The difference between the two SQLs lies in the UNIQUE part

Metadata

Metadata

Assignees

No one assigned

    Labels

    DDLDDL statement related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions