Alisher
Alisher

Reputation: 940

JOOQ Creating table with indices

As per documentation in order to create a table with JOOQ:

context.createTable("table")
      .column("column1", INTEGER)
      .column("column2", VARCHAR(10).nullable(false))
      .constraints(
          primaryKey("column1"),
          unique("column2"),
          foreignKey("column2").references("some_other_table"),
          check(field(name("column2")).like("A%"))
      )
      .execute();

However, it seems like that it's also possible to declare indices at table creation:

context.createTable("table")
      .column("column1", INTEGER)
      .column("column2", VARCHAR(10).nullable(false))
      .constraints(
          primaryKey("column1"),
          unique("column2"),
          foreignKey("column2").references("some_other_table"),
          check(field(name("column2")).like("A%"))
      )
      .indexes(...indices)
      .execute();

I can't find anything in documentation explaining how to do that.

What is a proper way to declare indicies this way?

Upvotes: 3

Views: 656

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221031

This particular syntax is not yet supported by jOOQ 3.15: https://github.com/jOOQ/jOOQ/issues/9243

You can implement it yourself in various ways, e.g.:

Alternatively, you can run two separate statements using the jOOQ DSL API:

  • CREATE TABLE
  • CREATE INDEX

Upvotes: 1

Related Questions