Timo
Timo

Reputation: 921

Accessing columns of manually declared aliased tables in JOOQ

I am manually declaring tables and fields for simple (but type safe) queries in JOOQ using:

Table<Record> myTable = DSL.table(DSL.name("my_table"));
Field<String> myField = DSL.field(DSL.name("my_table", "my_field"), String.class);

Creating an alias for myTable is easy:

Table<Record> myAlias = myTable.as("a");

But how can I access the value of myField within myAlias?

Note that myAlias.field(myField) will yield null, as the field is not part of this table definition.

Upvotes: 6

Views: 2429

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 221145

You cannot access fields from plain SQL tables, as jOOQ doesn't know anything about them. You'll have to construct individual field references for each alias, e.g.

Field<?> myAliasedField = field(name("a", "my_field"), String.class);

Upvotes: 6

Related Questions