jOOQ:“错误:关系CTE不存在”。

编程入门 行业动态 更新时间:2024-10-25 02:26:49
本文介绍了jOOQ:“错误:关系CTE不存在”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用jOOQ 3.11.2和Postgres 9.4,试图在第二个CTE的定义中重用一个jOOQ CTE。

Using jOOQ 3.11.2 and Postgres 9.4, I am trying to re-use one jOOQ CTE in the definition of a second CTE.

每个StackOverflow问题如何在jOOQ中重新使用一个CTE

The following is incorrect per StackOverflow question How to re-use one CTE in another CTE in jOOQ

CommonTableExpression<...> cteTwo = name().fields().as(select( with(cteOne ... ).from(cteOne) );

基于以上答案,我完全省略了cteTwo中的with(cteOne)子句。我尝试过:

Based on the above answer I omitted the with(cteOne) clause in cteTwo completely. I tried:

import static org.jooq.impl.DSL.*; CommonTableExpression<...> cteOne = name().fields().as(select(...); CommonTableExpression<...> cteTwo = name().fields().as(select().from(cteOne) ); // seem to need with(cteOne) here. List<someDTO> result = create .with(cteOne) .with(CteTwo) .select(...) .from(cteTwo) .fetchInto(someDTO.class);

上面的代码可以编译,但运行时出错:'jooq:错误的SQL语法。 ...错误:关系\ cteOne\不存在。'查看生成的SQL,在cteTwo中没有对cteOne的引用。

The above compiles but runs with error: 'jooq: bad SQL grammar. ... ERROR: relation \"cteOne\" does not exist.' Looking at the generated SQL, there is no reference to cteOne within cteTwo.

然后我尝试将与(cteOne)子句放在cteTwo定义内的不同位置。在SELECT子句之前只能尝试三个地方。没有一个是正确的:

Then I tried putting with(cteOne) clause in different places within inside the cteTwo definition. There are only three more places before the SELECT clause to try. None were correct:

CommonTableExpression<...> cteTwo = with(cteOne).name().fields().as(select( ... ).from(cteOne) ); CommonTableExpression<...> cteTwo = name() with(cteOne).fields().as(select( ... ).from(cteOne) ); CommonTableExpression<...> cteTwo = name().fields().with(cteOne).as(select( ... ).from(cteOne) );

请注意,这与定义多个CTE,然后在最终的select语句中使用每个CTE不同,如下所示:

Please note that this different from defining several CTE's and then using each CTE in a final select statement like so:

CommonTableExpression<...> cteAlpha = name(...).fields(...).as(select(...); CommonTableExpression<...> cteBeta = name(...).fields(...).as(select(...); List<SomeDTO> list = create .with(cteAlpha) .with(cteBeta) .select(...) from(cteAlpha, cteBeta).fetchInto(SomeDTO.class);

我的天堂应该怎么做?

I haven't found documentation or examples covering this precise point. How should this be done?

推荐答案

我正在回答我的问题到2020年1月1日,不可能将CTE链接起来。正如我在评论中指出的,解决方法是使用临时数据库表,在我的情况下,这是代码的味道,最后我解决了更大的问题。问题,简化了我的代码,不需要解决链接的CTE。

I am answering my own question. As of 1 Jan 2020, it was not possible to chain the CTEs. As I noted in the comments, the workaround was to use temp database tables. In my case that was a code smell. In the end I solved the bigger problem, simplified my code and did not need to solve chaining CTEs.

如果您使用临时表,请记住在不再需要时删除表以防止数据库混乱。

If you do use temp tables, remember to delete the tables when no longer needed to prevent database clutter.

请注意,jOOQ是一个维护良好且不断发展的库,在以后的版本中可能会添加。

Note that jOOQ is a well maintained evolving library and in later versions this might be added.

更多推荐

jOOQ:“错误:关系CTE不存在”。

本文发布于:2023-10-14 11:54:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1490986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不存在   错误   关系   jOOQ   CTE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!