Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -10456,14 +10456,15 @@ Index CreateTableConstraint():
}
{
(
LOOKAHEAD(3) (
{ idxSpec.clear(); }
LOOKAHEAD(4) (
{ idxSpec.clear(); tk3=null; }
[ tk3=<K_UNIQUE> ]
tk=<K_INDEX>
sk3=RelObjectName()
colNames = IndexColumnsWithParamsList()
( parameter=CreateParameter() { idxSpec.addAll(parameter); } )*
{
index = new Index().withType(tk.image).withName(sk3).withColumns(colNames).withIndexSpec(new ArrayList<String>(idxSpec));
index = new Index().withType((tk3!=null ? tk3.image + " " : "") + tk.image).withName(sk3).withColumns(colNames).withIndexSpec(new ArrayList<String>(idxSpec));
}
)
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,4 +1206,15 @@ void testCreateTableQuotedColumnNamedVisible() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(
"CREATE TABLE t1 (`visible` int, `invisible` varchar (10))", true);
}

@Test
void testUniqueIndexIssue1893() throws JSQLParserException {
// MySQL `UNIQUE INDEX name (cols) ...` was rejected (only INDEX / [UNIQUE] KEY were
// accepted).
assertSqlCanBeParsedAndDeparsed(
"CREATE TABLE t (a int, b int, UNIQUE INDEX idx (a, b) USING BTREE COMMENT 'unique index')",
true);
// A plain INDEX must still parse unchanged.
assertSqlCanBeParsedAndDeparsed("CREATE TABLE t (a int, INDEX idx (a))", true);
}
}
Loading