[英]How to use 'ANY' function with JOOQ
I currently use JOOQ to get data from postgresql DB.我目前使用 JOOQ 从 postgresql DB 获取数据。 Then I have faced a problem to get data which data-type is array type.
然后我遇到了获取数据类型为数组类型的数据的问题。
Current condition is like below:目前情况如下:
Table schema is:表架构是:
CREATE TABLE favorites (
id int,
items varchar(100)[]
);
Sample data is:样本数据是:
INSERT INTO favorites (id, items)
VALUES (1, '{orange, lemon, banana}');
INSERT INTO favorites (id, items)
VALUES (2, '{apple, grape}');
To get first data, SQL is like:要获取第一个数据,SQL 就像:
SELECT id, items FROM favorites WHERE 'orange' = ANY (items);
But, I cannot create sql like above with JOOQ.但是,我无法使用 JOOQ 像上面那样创建 sql。
Connection connection = ...;
DSLContext context = DSL.using(connection, ...);
List<Table> table = context.select().from(TABLE).fetchInto(class.TABLE);
Can I use ANY function with JOOQ?我可以在 JOOQ 中使用任何功能吗? If it is possible, how can I create it with JOOQ.
如果可能,我如何使用 JOOQ 创建它。 If not, is there any other ways to get the same result with JOOQ?
如果没有,还有其他方法可以用 JOOQ 获得相同的结果吗?
Thank you in advance.先感谢您。
Do it like this:像这样做:
List<TableRecord> table = context
.selectFrom(TABLE)
.where(val("orange").eq(any(TABLE.ITEMS)))
.fetch();
The above query uses DSL.any(Field<T[]>)
上面的查询使用
DSL.any(Field<T[]>)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.