Search code examples
javapostgresqlpostgisjooq

Specify methods for use in index creation


Using PostGIS, you may create an index with the following;

CREATE INDEX mytable_gix
ON mytable
USING GIST (myCol);

Using JOOQ, I have access to methods such as createIndexIfNotExists

How can I maintain the method usage USING GIST with something like;

dslContext
.createIndexIfNotExists("table_gix")
.on("table")
.execute();

Solution

  • As of jOOQ 3.13, this syntax is not supported in the DSL API yet. You'll have to roll your own, using plain SQL templating:

    dslContext.execute("create index mytable_gix on mytable using gist (mycol)");
    

    If you have generated objects from your schema that you'd like to reuse, use the templating features:

    dslContext.execute(
      "create index {0} on {1} using gist ({2})", 
      name("mytable_gix"),
      MYTABLE,
      MYTABLE.MYCOL.getUnqualifiedName()
    );