Skip to content

Commit 2ce72a3

Browse files
Fix: Support Drop Key (#1917)
* Fix: Support Drop Key * Fix: Support Drop Key * Fix
1 parent 2ae1d53 commit 2ce72a3

File tree

3 files changed

+164
-99
lines changed

3 files changed

+164
-99
lines changed

src/main/java/net/sf/jsqlparser/statement/create/table/Index.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,11 @@ public String getType() {
8181
}
8282

8383
/**
84-
* In postgresql, the index type (Btree, GIST, etc.) is indicated
85-
* with a USING clause.
86-
* Please note that:
87-
* Oracle - the type might be BITMAP, indicating a bitmap kind of index
88-
* MySQL - the type might be FULLTEXT or SPATIAL
89-
* @param using
84+
* In postgresql, the index type (Btree, GIST, etc.) is indicated with a USING clause. Please
85+
* note that: Oracle - the type might be BITMAP, indicating a bitmap kind of index MySQL - the
86+
* type might be FULLTEXT or SPATIAL
87+
*
88+
* @param using
9089
*/
9190
public void setUsing(String using) {
9291
this.using = using;
@@ -135,8 +134,15 @@ public Index withIndexSpec(List<String> idxSpec) {
135134
@Override
136135
public String toString() {
137136
String idxSpecText = PlainSelect.getStringList(idxSpec, false, false);
138-
return ( type!=null ? type : "") + (!name.isEmpty() ? " " + getName() : "") + " " + PlainSelect.
139-
getStringList(columns, true, true) + (!"".equals(idxSpecText) ? " " + idxSpecText : "");
137+
String head = (type != null ? type : "") + (!name.isEmpty() ? " " + getName() : "");
138+
String tail = PlainSelect.getStringList(columns, true, true)
139+
+ (!"".equals(idxSpecText) ? " " + idxSpecText : "");
140+
141+
if ("".equals(tail)) {
142+
return head;
143+
}
144+
145+
return head + " " + tail;
140146
}
141147

142148
public Index withType(String type) {

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6392,7 +6392,7 @@ AlterExpression AlterExpression():
63926392
)
63936393
|
63946394
(
6395-
tk=<K_INDEX>
6395+
( tk=<K_INDEX> | tk=<K_KEY> )
63966396
( tk2=<S_IDENTIFIER> | tk2=<S_QUOTED_IDENTIFIER> ) {
63976397
index = new Index().withType(tk.image).withName(tk2.image);
63986398
alterExp.setIndex(index);

0 commit comments

Comments
 (0)