rxjava2-jdbc
rxjava2-jdbc copied to clipboard
defaultIfEmpty() possibly buggy...
Hello there!
I'm getting
java.lang.RuntimeException: onNext called with null. Null values are generally not allowed in 2.x operators and sources.
When the select doesn't have any retuned value (null
), shouldn't it default to -1 instead of passing on null
?
return database
.select("SELECT SUM(amount) FROM table")
.parameter("param1", param1)
.parameter("param2", param2)
.getAs(BigDecimal.class)
.defaultIfEmpty(new BigDecimal(-1));
Once again thank you thank you for your time!
Got it to work with a SQL workaround (PostgreSQL DB)
SELECT (CASE WHEN SUM(amount) ISNULL THEN -1 ELSE SUM(amount) END) FROM table
You can also use .getAsOptional(BigDecimal.class)
. See doco at https://github.com/davidmoten/rxjava2-jdbc#nulls.
Thank you for the reference! It didn't even cross my mind 👍