rxjava2-jdbc icon indicating copy to clipboard operation
rxjava2-jdbc copied to clipboard

defaultIfEmpty() possibly buggy...

Open Mu4h4h4 opened this issue 7 years ago • 3 comments

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!

Mu4h4h4 avatar Jan 23 '18 04:01 Mu4h4h4

Got it to work with a SQL workaround (PostgreSQL DB) SELECT (CASE WHEN SUM(amount) ISNULL THEN -1 ELSE SUM(amount) END) FROM table

Mu4h4h4 avatar Jan 23 '18 18:01 Mu4h4h4

You can also use .getAsOptional(BigDecimal.class). See doco at https://github.com/davidmoten/rxjava2-jdbc#nulls.

davidmoten avatar Jan 24 '18 02:01 davidmoten

Thank you for the reference! It didn't even cross my mind 👍

Mu4h4h4 avatar Jan 24 '18 19:01 Mu4h4h4