I am using jOOQ with a temporary table:
Table TMP = DSL.table(\"tmp\");
Field TYPE = DSL.field(\"type\", String.class);
Field
There are two ways to interact with tables / columns dynamically (i.e. without using the code generator) in jOOQ:
org.jooq.SQL
)That's what you're doing. You can obviously qualify the columns directly in your plain SQL Field
references in two ways:
By repeating the "tmp"
string in each field:
Table<Record> TMP = DSL.table("tmp");
Field<String> TYPE = DSL.field("tmp.type", String.class);
Field<String> TOKEN = DSL.field("tmp.token", String.class);
By embedding the "tmp"
reference in the plain SQL template:
Table<Record> TMP = DSL.table("tmp");
Field<String> TYPE = DSL.field("{0}.type", String.class, TMP);
Field<String> TOKEN = DSL.field("{0}.token", String.class, TMP);
The plain SQL functionality is documented here in the manual
org.jooq.Name
)That's probably what you want to be doing instead. You'll write:
Table<Record> TMP = DSL.table(DSL.name("tmp"));
Field<String> TYPE = DSL.field(DSL.name("tmp", "type"), String.class);
Field<String> TOKEN = DSL.field(DSL.name("tmp", "token"), String.class);
The naming functionality is described here in the manual.
The advantages of this approach are: