postgres 查询:
select * from message t where "address" = decode('0x159159159526212521','escape')
开发代码:
Field<String> address = val("0x159159159526212521");
Field<String> escape = val("escape");
rdbmsJooqContext.select(
al.NAME.as("name"),
al.ADDRESS.as("address")
).from(al)
.where(
condition(" 'address' = decode({0}, {1})", address, escape)
).fetchInto(AddressLabelResult.class);
jooq查询结果:
where ( 'address' = decode('0x159159159526212521', 'escape'))
我要jooq查询结果:
where 'address' = decode('0x159159159526212521', 'escape')
如何删除“where sql” '(' and ')' ??
当您使用某种类型的纯 SQL 模板时,例如
Condition
,jOOQ 将始终将它们括在括号中以确保模板不会被运算符优先级规则破坏。想象一下
al.NAME.eq("x").and( condition("something or something_else") )
如您所见,普通 SQL 模板被传递给
and()
方法,因此预期其内容应具有比 AND
运算符更高的优先级。在这种情况下,您希望结果是:
name = 'x' and ( something or something_else )
不是这个(
and
现在比 or
有更高的优先级):
name = 'x' and something or something_else
假设这些括号有时是不必要的,只是一个表面问题,就像你的情况一样。
如果你真的不喜欢谓词周围的括号,你可以解决它,例如通过写这个:
inline("address").eq(field("decode({0}, {1})", String.class, address, escape)
相同位置的
Field
模板没有实现相同的括号逻辑。