Handle null values in queries
masterRxJava2 does not support streams of null values. To handle nullable columns, use the following strategies:
- Single nullable column: Use
getAsOptional(Class<T> type)to return ajava.util.Optional. - Multiple columns: Nulls are supported when mapping to
Tupleinstances. - Null parameters: Use
Parameter.NULLorDatabase.NULL_CLOB/Database.NULL_BLOBfor updates.
// Using getAsOptional for a single nullable column
Database.test()
.select("select date_of_birth from person where name='FRED'")
.getAsOptional(Instant.class)
.blockingForEach(System.out::println);
// Using explicit null parameter
Database.test()
.update("update person set date_of_birth = ?")
.parameter(null)
.counts()
.blockingForEach(System.out::println);