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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With