This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
A slightly different use case than CAST expressions are data type coercions, which are not rendered through to generated SQL. Sometimes, you may want to pretend that a numeric value is really treated as a string value, for instance when binding a numeric bind value:
Field<String> field1 = val(1).coerce(String.class); Field<Integer> field2 = val("1").coerce(Integer.class);
In the above example,
field1 will be treated by jOOQ as a
Field<String>, binding the numeric literal
1 as a
VARCHAR value. The same applies to
field2, whose string literal
"1" will be bound as an
This technique is better than performing unsafe or rawtype casting in Java, if you cannot access the "right" field type from any given expression.