Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of jOOQ query with more than 22 columns

Tags:

java

sql

jooq

I'm looking for examples of how I can execute a jOOQ query with more than 22 rows.

http://www.jooq.org/doc/latest/manual/sql-building/column-expressions/row-value-expressions/

tells me it's possible, but I haven't been able to find an example.

Can anyone point me in the right direction?

like image 691
danielc Avatar asked Dec 03 '15 22:12

danielc


Video Answer


1 Answers

As of jOOQ 3.7 (and there are currently no plans to change this), 22 is the maximum number of columns that can be fetched in a type safe way. Beyond 22, you can still execute queries, but jOOQ's API will no longer track the type of your records. For example:

// Still type safe
Result<Record22<Integer, String, ..., Integer>> result =
DSL.using(configuration)
   .select(INT_COLUMN1, STRING_COLUMN2, ..., INT_COLUMN22)
   .from(TABLE)
   .fetch();

// Add one more column, and "lose" type safety
Result<Record> result =
DSL.using(configuration)
   .select(INT_COLUMN1, STRING_COLUMN2, ..., INT_COLUMN22, STRING_COLUMN23)
   .from(TABLE)
   .fetch();

From an API user perspective, the API "feels" exactly the same way, regardless if you select 22 or less columns (type safely), or 23 or more columns (without type safety).

Losing type safety with UNION

The difference might become most apparent when you compare type safe UNION queries with non-type safe ones:

// Still type safe
Result<Record22<Integer, String, ..., Integer>> result =
DSL.using(configuration)
   .select(INT_COLUMN1, STRING_COLUMN2, ..., INT_COLUMN21)
   .from(TABLE)
   .union(
//  ^^^^^ compilation error here
    select(INT_COLUMN1, STRING_COLUMN2, ..., INT_COLUMN21, INT_COLUMN22)
   .from(TABLE))
   .fetch();

// Add one more column, and "lose" type safety
Result<Record> result =
DSL.using(configuration)
   .select(INT_COLUMN1, STRING_COLUMN2, ..., STRING_COLUMN23)
   .from(TABLE)
   .union(
//  ^^^^^ This compiles, even if it's wrong
    select(INT_COLUMN1, STRING_COLUMN2, ..., STRING_COLUMN23, STRING_COLUMN24)
   .from(TABLE))
   .fetch();
like image 82
Lukas Eder Avatar answered Sep 29 '22 08:09

Lukas Eder