jOOQ 是否支持查询本地结果?

does jOOQ support querying on local results?

假设您已经从数据库中获取了一些数据:

Record r = <DSLContext>.select()...fetch();

jOOQ是否支持对结果进行进一步的本地查询?

<DSLContext>.select(...).from(r).where(...)...fetch();

有时,基于先前对数据库的查询在本地查询结果是有意义的。

我在文档中找不到任何有用的东西,所以我想答案是否定的。但是,无论如何,我在这里问它,以确定并可能引发一些关于此功能的想法或讨论(尽管这不是 SO 的目的)。

如果你真的想要另一个数据库往返,那么是的,你可以创建一个新的 org.jooq.Table from a org.jooq.Result using DSL.table(Result):

select(...)
.from(DSL.table(result))
.where(...)
.fetch();

如果您的数据库支持,这将使用 SQL VALUES(...) constructor 生成 table,或者使用 UNION ALL 生成派生的 table,否则:

-- If database supports VALUES()
SELECT ...
FROM (VALUES (1, 'a'),
             (2, 'b'),
             (3, 'c')) t(column1, column2)
WHERE ...

-- Otherwise
SELECT ...
FROM (SELECT 1 column1, 'a' column2 UNION ALL
      SELECT 2        , 'b'         UNION ALL
      SELECT 3        , 'c') t
WHERE ...

-- actual SQL may vary, of course

采用 Record 而不是 Result 的替代版本在 jOOQ 3.6 的路线图上:#4009. In the meantime, you'll have to either use the original Result reference, or create a new instance using one of the DSLContext.newResult(...) 方法。