Using DSL.row() in update statement with nullable properties.

137 views
Skip to first unread message

Cheolho Jeon

unread,
Oct 1, 2021, 7:08:43 AM10/1/21
to jOOQ User Group
Hi Lukas!
Thank you for serving JOOQ.

I'm using JOOQ for project but I see a problem when I use update statement with DSL.row().
I want to use some nullable property(field) to DSL.row() on update statement like this:
update(CLAIM)
.set(
    row(CLAIM.DESIRED_DATETIME, ...),
    row(null as LocalDateTime?, ...)
)
...

But when I run this code I met this error:
Caused by: java.lang.IllegalArgumentException: Cannot encode null parameter of type java.lang.Object
at io.r2dbc.postgresql.codec.DefaultCodecs.encodeNull(DefaultCodecs.java:184)

I found that this code is run well:
update(CLAIM)
.set(
    CLAIM.DESIRED_DATETIME, null as LocalDateTime?
)
...

But I want to set multiple nullable properties(fields) at once.
Can you tell me the way resolve this problem?

Thank you.

P.S All code is written by Kotlin.
carbon-17.png
carbon-16.png

Lukas Eder

unread,
Oct 1, 2021, 7:11:41 AM10/1/21
to jOOQ User Group
Hi Cheolho,

There are some open issues related to using null values inside of row() expressions, when jOOQ can't infer the data type even if intuitively, it should work. The workaround is to wrap the null value in DSL.value(null, dataType), to make sure the right data type is associated with the value.

I hope this helps,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/715359eb-c12b-4676-b671-fd57a6f20140n%40googlegroups.com.

Cheolho Jeon

unread,
Oct 1, 2021, 8:56:35 AM10/1/21
to jOOQ User Group
Thank you Lukas

It works well :)

2021년 10월 1일 금요일 오후 8시 11분 41초 UTC+9에 lukas...@gmail.com님이 작성:

Lukas Eder

unread,
Mar 14, 2022, 6:10:25 AM3/14/22
to jOOQ User Group
I stumbled upon this again. I've created an issue for this problem:

It seems to happen with R2DBC only, not with JDBC (at least not in my test case). Nonetheless, I think it would be better to use any explicit DataType available on the left-hand-side ROW expression and apply those to the right-hand-side, as well.

Reply all
Reply to author
Forward
0 new messages