java - How to get all the result columns from database with other custom(concat, sum, count) columns in Jooq -
i have table table1 6 columns.
here sql statement need map.
select *,count(id) idcount table1;
now, sql query result 7 columns ( 6 table1 columns , 1 idcount column). when implement same in jooq query, gets single column "idcount".
selectquery q = factory.selectquery(); q.addselect(table1.id.count().as("idcount")); q.addfrom(table1.table1);
now, resultant recordset have single column "idcount" while need columns , 1 additional column "idcount". want 7 columns in jooq too.
the *
(asterisk, star) operator not explicitly supported jooq. however, have 3 options map sql statement jooq:
option 1 (with dsl syntax):
list<field<?>> fields = new arraylist<field<?>>(); fields.addall(arrays.aslist(table1.table1.fields())); fields.add(table1.id.count().as("idcount")); select<?> select = factory.select(fields).from(table1.table1);
option 2 (with "regular" syntax, used):
selectquery q = factory.selectquery(); q.addselect(table1.table1.fields()); q.addselect(table1.id.count().as("idcount")); q.addfrom(table1.table1);
option 3 (added in later version of jooq):
// convenience, can specify several "select" clauses factory.select(table1.table1.fields()) .select(table1.id.count().as("idcount") .from(table1.table1);
note jooq 2.x's getfields()
method renamed fields()
in jooq 3.0
Comments
Post a Comment