简体   繁体   中英

How can I get fields from a non-generated, aliased table?

Table<Record> myTable = DSL.table("myTable");
Table<Record> a = myTable.as("a");
Field<Integer> myField = DSL.field("myField", SQLDataType.INTEGER);

a.field("myField"); // == null
a.field("myField", SQLDataType.INTEGER); // == null
a.field(myField); // == null

I want to use a table expression in a comparison, similar to this . I am using jOOQ just to generate SQL strings; I am not using its code generation for my table types.

I just now saw this comment in the documentation:

A better solution would be any of these:

 Field MY_FIELD1 = field(MY_TABLE.getName() + ".MY_FIELD"); Field MY_FIELD2 = field(name(MY_TABLE.getName(), "MY_FIELD")); 

I think that this section of the manual might be quite helpful for you: http://www.jooq.org/doc/latest/manual/sql-building/names

This worked for me, but I needed to make some changes because I'm using type-safe fields. I wrote this helper:

private <T> Field<T> field(final Table<Record> table, final Field<T> field) {
    return DSL.field(DSL.name(table.getName(), field.getName()), field.getDataType());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM