[英]How to execute specific query using jOOQ
I am using jOOQ in my project that is working with PostgreSQL database. 我在使用PostgreSQL数据库的项目中使用jOOQ。 I don't have any problems with query execution without specific condition, but how can I execute the following query with jOOQ ?
没有特定条件的查询执行没有任何问题,但是如何使用jOOQ执行以下查询?
-- missed the top of query
WHERE pow.tags @> ARRAY [?]
AND pow.tags @> ARRAY [?]
AND position('access,yes' IN array_to_string(pow.tags, ',')) = 0
AND city = ?
Sometimes, I need to execute requests with PostGIS
functions, how must I write its in jOOQ? 有时,我需要使用
PostGIS
函数执行请求,如何在jOOQ中编写请求?
Here's how to write that predicate: 编写谓词的方法如下:
Condition condition =
POW.TAGS.contains(new String[] { "a", "b", "c" })
.and(POW.TAGS.contains(new String[] { "b", "c", "d" }) // Just assuming some tags here
.and(position("access,yes", arrayToString(POW.TAGS, ",")).eq(zero()))
.and(POW.CITY.eq("city"));
The above answer is assuming the following static imports: 上面的答案假设以下静态导入:
import static org.jooq.impl.DSL.*;
import static org.jooq.util.postgres.PostgresDSL.*;
Field.contains()
Field.contains()
可能存在的问题 There's a known issue with Field.contains()
in the event when your TAGS
column is of type TEXT
, rather than VARCHAR
: 如果您的
TAGS
列的类型为TEXT
而不是VARCHAR
,则Field.contains()
存在一个已知问题:
https://github.com/jOOQ/jOOQ/issues/4754 https://github.com/jOOQ/jOOQ/issues/4754
The workaround is to use plain SQL: 解决方法是使用普通的SQL:
public static Condition myContains(Field<String[]> field, String[] array) {
return contains("{0} @> {1}", field, val(array));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.