我使用JOOQ-3.1.0生成和执行Spring-4的Oracle和Postgresql的动态查询。在一个场景中,我有一个分区表,需要使用JOOQ进行查询。我使用DSL.tableByName(vblTablename);,其中vblTablename是查询生成方法ex,vbl_default partition(p_04-Dec-14)中作为字符串接收的字符串。(不同数据库的vblTablename模式不同,并在外部属性文件中进行配置)。JOOQ生成sql,但在表名周围使用双引号。查询和错误如下所示
查询
SELECT COUNT(ID) COUNT FROM "vbl_default partition(p_04-Dec-14)"
where (rts between timestamp '2014-12-04 00:00:00.0' and timestamp '2014-12-05 00:00:00.0' and userid in (2))错误
ORA-00972: identifier is too long
00972. 00000 - "identifier is too long"
*Cause: An identifier with more than 30 characters was specified.
*Action: Specify at most 30 characters.
Error at Line: 4 Column: 29虽然我已经在DefaultDSLContext上设置了以下设置
Settings settings = new Settings();
settings.setRenderNameStyle(RenderNameStyle.AS_IS);我如何删除桌子周围的引号?还有其他设置我错过了吗?
发布于 2014-12-08 11:19:02
DSL.tableByName(String...)背后的想法是你提供一张桌子.按姓名:-)
您要寻找的是一个普通的SQL表,通过DSL.table(String)。
你可以写:
// Assuming this import
import static org.jooq.impl.DSL.*;
DSL.using(configuration)
.select(count(VBL_DEFAULT.ID))
.from(table("vbl_default partition(p_04-Dec-14)"))
.where(...);或者使用方便的重载SelectFromStep.from(String)
DSL.using(configuration)
.select(count(VBL_DEFAULT.ID))
.from("vbl_default partition(p_04-Dec-14)")
.where(...);有关jOOQ中普通SQL的更多信息可以从以下手册页面获得:
http://www.jooq.org/doc/latest/manual/sql-building/plain-sql/
分区支持
注意,对Oracle分区的支持在路线图上:#2775。同时,如果希望更频繁地使用分区表,也可以编写自己的函数:
// Beware of the risk of SQL injection, though!
public <R extends Record> Table<R> partition(Table<R> table, String partition) {
return DSL.table("{0} partition(" + partition + ")", table);
}..。然后:
DSL.using(configuration)
.select(count(VBL_DEFAULT.ID))
.from(partition(VBL_DEFAULT, "p_04-Dec-14"))
.where(...);https://stackoverflow.com/questions/27353734
复制相似问题