jOOQ - support for UPDATE … SET … query with arbit

2019-08-08 19:29发布

I have two functions: one returns a list of fields, the other returns a select query (which selects the corresponding values of the fields).

private List<Field<?>> fields() {
    ....
}

private Select<?> select() {
    ...
}

Note that the degree is determined at runtime, it depends on the user input. Hence List<Field<?>> and Select<?>.

It is possible to insert into a table:

context.insertInto(table, fields()).select(select()))

It is not possible to update a table:

context.update(table).set(DSL.row(fields()), select())

Could this functionality be added to jOOQ 3.7?

Which workaround can we use for now?

1条回答
再贱就再见
2楼-- · 2019-08-08 20:13

Nice catch, there's a missing method on the UpdateSetFirstStep DSL API, which accepts RowN as a first argument, the type returned from DSL.row(Collection). This should be fixed for jOOQ 3.7: https://github.com/jOOQ/jOOQ/issues/4475

As a workaround, and if you can live with the guilt of the hack, you could cast to raw types:

context.update(table).set((Row1) DSL.row(fields()), (Select) select())

You can cast DSL.row(fields()) to Row1, because the internal implementation type returned by DSL.row(fields()) implements all Row[N] types.

查看更多
登录 后发表回答