我有一个JSONB列,它包含字符串数组,例如:["foo", "bar"]
我想写jOOQ相当于:
SELECT * FROM sometable WHERE somecolumn ?| <mylist>
...应该绑定到java字符串标记名列表。
似乎没有直接支持?|在jOOQ 3.8。我已经看过在一个条件下绑定到原始sql,但我不太确定语法;如果尝试使用与绑定表达式冲突的?
postgres运算符,情况会更糟。
更新:堆栈跟踪3.8.3
我把它剥离到最低限度的测试。使用jOOQ 3.8.3添加这样的条件时:
query.addConditions(DSL.condition("sometable.tags ?| array['sometag']"));
生成这样的堆栈跟踪:
Caused by: org.postgresql.util.PSQLException: No value specified for parameter 1.
at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:228)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:163)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:622)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:472)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:465)
at org.jooq.tools.jdbc.DefaultPreparedStatement.execute(DefaultPreparedStatement.java:194)
at org.jooq.impl.AbstractResultQuery.execute(AbstractResultQuery.java:269)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:348)
... 36 more
答案 0 :(得分:2)
与jOOQ解析?|
和类似运算符作为绑定变量相关的问题已在jOOQ 3.8.3中得到解决:https://github.com/jOOQ/jOOQ/issues/5307
注意,除上述内容外,还有a JDBC limitation that I have documented in a separate question。在jOOQ中,您可以通过指定:
来解决此JDBC限制Settings settings = new Settings().withStatementType(StatementType.STATIC_STATEMENT);
另请参阅:http://www.jooq.org/doc/latest/manual/sql-execution/statement-type
或者,通过回退使用jsonb_exists_any()
函数而不是?|
运算符。