Skip to content

Commit

Permalink
Fix: Support Drop Key (#1917)
Browse files Browse the repository at this point in the history
* Fix: Support Drop Key

* Fix: Support Drop Key

* Fix
  • Loading branch information
jxnu-liguobin authored Dec 14, 2023
1 parent 2ae1d53 commit 2ce72a3
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 99 deletions.
22 changes: 14 additions & 8 deletions src/main/java/net/sf/jsqlparser/statement/create/table/Index.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ public String getType() {
}

/**
* In postgresql, the index type (Btree, GIST, etc.) is indicated
* with a USING clause.
* Please note that:
* Oracle - the type might be BITMAP, indicating a bitmap kind of index
* MySQL - the type might be FULLTEXT or SPATIAL
* @param using
* In postgresql, the index type (Btree, GIST, etc.) is indicated with a USING clause. Please
* note that: Oracle - the type might be BITMAP, indicating a bitmap kind of index MySQL - the
* type might be FULLTEXT or SPATIAL
*
* @param using
*/
public void setUsing(String using) {
this.using = using;
Expand Down Expand Up @@ -135,8 +134,15 @@ public Index withIndexSpec(List<String> idxSpec) {
@Override
public String toString() {
String idxSpecText = PlainSelect.getStringList(idxSpec, false, false);
return ( type!=null ? type : "") + (!name.isEmpty() ? " " + getName() : "") + " " + PlainSelect.
getStringList(columns, true, true) + (!"".equals(idxSpecText) ? " " + idxSpecText : "");
String head = (type != null ? type : "") + (!name.isEmpty() ? " " + getName() : "");
String tail = PlainSelect.getStringList(columns, true, true)
+ (!"".equals(idxSpecText) ? " " + idxSpecText : "");

if ("".equals(tail)) {
return head;
}

return head + " " + tail;
}

public Index withType(String type) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -6392,7 +6392,7 @@ AlterExpression AlterExpression():
)
|
(
tk=<K_INDEX>
( tk=<K_INDEX> | tk=<K_KEY> )
( tk2=<S_IDENTIFIER> | tk2=<S_QUOTED_IDENTIFIER> ) {
index = new Index().withType(tk.image).withName(tk2.image);
alterExp.setIndex(index);
Expand Down
Loading

0 comments on commit 2ce72a3

Please sign in to comment.