I have a problem with jooq version 3.14.6. I wanna to use an update statement for fields search - pr_id and m_id like this:
public Result<?> save(Long id, Request req) {
Condition condition = field("send.pr_id").eq(id)
.and(field("send.m_id").eq(req.getMemId));
condition = req.applyConditions(condition);
return ctx.update(table(snp).as("send"))
.set(field("status"), "D")
.where(condition)
.returning()
.fetch();
}
Also in class Request i have this code:
public class Request {
Integer prId;
List<Long> memId;
public Condition applyConditions(Condition condition) {
Condition mod = condition;
if(Objects.nonNull(prId)) {
mod = mod.and(field("send.pr_id")).eq(prId);
}
if(Objects.nonNull(memId)) {
mod = mod.and(field("send.m_id")).eq(memId);
}
return modified;
}
}
in my table i have columns - pr_id bigint not null, status char(1) not null, m_id bigint not null etc..
When i start my project and use rest request(http://localhost:8080/api/v1/pr/17) in postman like so:
{ "memId": [ 2, 4, 6 ] }
i get error:
"Type class java.util.ArrayList is not supported in dialect postgres"
This error tied with uncorrect field memId
How can i correct this code?
You cannot compare a column with a list in SQL, using =
. Just use the IN
predicate instead:
field("send.m_id").in(memId)
Please note: I strongly recommend you use jOOQ with code generation, unless your schema is dynamic. But given you're passing constant string literals for your table/column names, it probably isn't.