1212import static java .util .stream .Collectors .joining ;
1313
1414import java .util .*;
15+ import net .sf .jsqlparser .expression .Expression ;
1516import net .sf .jsqlparser .schema .*;
1617import net .sf .jsqlparser .statement .*;
1718import net .sf .jsqlparser .statement .create .table .*;
19+ import net .sf .jsqlparser .statement .select .PlainSelect ;
1820
1921public class CreateIndex implements Statement {
2022
@@ -25,6 +27,11 @@ public class CreateIndex implements Statement {
2527 private boolean usingIfNotExists = false ;
2628 private boolean concurrently ;
2729 private boolean only ;
30+ private List <String > includeColumns ;
31+ private Boolean nullsDistinct ;
32+ private List <Index .Option > storageParameters ;
33+ private String tableSpace ;
34+ private Expression where ;
2835
2936 public boolean isIndexTypeBeforeOn () {
3037 return indexTypeBeforeOn ;
@@ -59,6 +66,46 @@ public void setOnly(boolean only) {
5966 this .only = only ;
6067 }
6168
69+ public List <String > getIncludeColumns () {
70+ return includeColumns ;
71+ }
72+
73+ public void setIncludeColumns (List <String > includeColumns ) {
74+ this .includeColumns = includeColumns ;
75+ }
76+
77+ public Boolean getNullsDistinct () {
78+ return nullsDistinct ;
79+ }
80+
81+ public void setNullsDistinct (Boolean nullsDistinct ) {
82+ this .nullsDistinct = nullsDistinct ;
83+ }
84+
85+ public List <Index .Option > getStorageParameters () {
86+ return storageParameters ;
87+ }
88+
89+ public void setStorageParameters (List <Index .Option > storageParameters ) {
90+ this .storageParameters = storageParameters ;
91+ }
92+
93+ public String getTableSpace () {
94+ return tableSpace ;
95+ }
96+
97+ public void setTableSpace (String tableSpace ) {
98+ this .tableSpace = tableSpace ;
99+ }
100+
101+ public Expression getWhere () {
102+ return where ;
103+ }
104+
105+ public void setWhere (Expression where ) {
106+ this .where = where ;
107+ }
108+
62109 @ Override
63110 public <T , S > T accept (StatementVisitor <T > statementVisitor , S context ) {
64111 return statementVisitor .visit (this , context );
@@ -135,6 +182,8 @@ public String toString() {
135182
136183 buffer .append (")" );
137184
185+ appendPostgreSqlTail (buffer );
186+
138187 if (tailParameters != null ) {
139188 for (String param : tailParameters ) {
140189 buffer .append (" " ).append (param );
@@ -145,6 +194,25 @@ public String toString() {
145194 return buffer .toString ();
146195 }
147196
197+ private void appendPostgreSqlTail (StringBuilder buffer ) {
198+ if (includeColumns != null ) {
199+ buffer .append (" INCLUDE (" ).append (String .join (", " , includeColumns )).append (")" );
200+ }
201+ if (nullsDistinct != null ) {
202+ buffer .append (" NULLS " ).append (nullsDistinct ? "DISTINCT" : "NOT DISTINCT" );
203+ }
204+ if (storageParameters != null ) {
205+ buffer .append (" WITH " )
206+ .append (PlainSelect .getStringList (storageParameters , true , true ));
207+ }
208+ if (tableSpace != null ) {
209+ buffer .append (" TABLESPACE " ).append (tableSpace );
210+ }
211+ if (where != null ) {
212+ buffer .append (" WHERE " ).append (where );
213+ }
214+ }
215+
148216 public CreateIndex withTable (Table table ) {
149217 this .setTable (table );
150218 return this ;
@@ -169,4 +237,29 @@ public CreateIndex withOnly(boolean only) {
169237 setOnly (only );
170238 return this ;
171239 }
240+
241+ public CreateIndex withIncludeColumns (List <String > includeColumns ) {
242+ setIncludeColumns (includeColumns );
243+ return this ;
244+ }
245+
246+ public CreateIndex withNullsDistinct (Boolean nullsDistinct ) {
247+ setNullsDistinct (nullsDistinct );
248+ return this ;
249+ }
250+
251+ public CreateIndex withStorageParameters (List <Index .Option > storageParameters ) {
252+ setStorageParameters (storageParameters );
253+ return this ;
254+ }
255+
256+ public CreateIndex withTableSpace (String tableSpace ) {
257+ setTableSpace (tableSpace );
258+ return this ;
259+ }
260+
261+ public CreateIndex withWhere (Expression where ) {
262+ setWhere (where );
263+ return this ;
264+ }
172265}
0 commit comments