Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Meow-Cat opened this issue Nov 24, 2023 · 1 comment
Labels
DDL DDL statement related

Comments

@Meow-Cat
Copy link

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

@manticore-projects
Copy link
Contributor

Greetings,

your particular Index clause is unsupported. Please check the supported Syntax here:
http://manticore-projects.com/jsqlformatter/JSQLFormatter/syntax.html#createindex

You can also test your statement online and interactively here.

@manticore-projects manticore-projects added the DDL DDL statement related label Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DDL DDL statement related
Projects
None yet
Development

No branches or pull requests

2 participants