我正在嘗試使用 Java 中的 jooq api 將 POSTGRES sql 轉換為 H2。我是這個圖書館的新手。誰能告訴我我在這里做錯了什么?這是我的代碼:
Query query = DSL
.using(SQLDialect.POSTGRES)
.parser()
.parseQuery("select split_part(some_field, '@', 2) from test");
String convertedQuery = DSL.using(SQLDialect.H2).render(query));
我正在使用 jooq 依賴版本 3.13.6 從https://www.jooq.org/translate/嘗試時相同的 sql作業正常,但我的代碼拋出以下例外:
java.lang.Exception: 未知函式: [1:21] SELECT SPLIT_PART ( [ ]OPACKET_SC_EMAILADDRESSDECRYPTED , '@' , 2 ) FROM TEST MT*
我想從代碼中啟用“決議未知函式”,我該如何實作?
uj5u.com熱心網友回復:
我想出了如何啟用“決議未知函式”,但是無法識別諸如 date_diff 和 date_parse 之類的某些函式。有什么線索嗎?
uj5u.com熱心網友回復:
jOOQ ParseListenerSPI可用于向 jOOQ 的決議器添加新功能,例如在您的情況下:
Query query = configuration
.derive(ParseListener.onParseCondition(ctx -> {
if (ctx.parseFunctionNameIf("SPLIT_PART")) {
ctx.parse('(');
Field<?> f1 = ctx.parseField();
ctx.parse(',');
Field<?> f2 = ctx.parseField();
ctx.parse(',');
Field<?> f3 = ctx.parseField();
ctx.parse(')');
return ... // implement your emulation here
}
// Let the parser take over if we don't know the token
return null;
})
.dsl()
.parser()
.parseQuery("select split_part(some_field, '@', 2) from tes");
此功能需要 jOOQ 3.15 商業版
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/336703.html
