Jeremy Ross
Jeremy Ross

Reputation: 11600

jOOQ: How can I include a "some_field IS NULL" predicate in the projection?

This compiles, but it seems a bit roundabout:

List<Field<?>> selectFields = new ArrayList<>();
selectFields.add(DSL.field(MY_TABLE.SOME_FIELD.isNull()).as("field_alias"));

The field() call is required because isNull() returns a Condition, whereas I think I need a Field. Is there a better way? Maybe an isNull() that returns something that can be used directly in a select()?

Upvotes: 2

Views: 2167

Answers (1)

Lukas Eder
Lukas Eder

Reputation: 220877

DSL.field(Condition) (which you're already using) is the way to go here.

There have been contemplations about letting Condition extends Field<Boolean>: https://github.com/jOOQ/jOOQ/issues/3867, but the change would be too risky in terms of backwards compatibility.

Upvotes: 3

Related Questions