Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose new SQL function in JOOQ

Tags:

java

sql

jooq

I want to use REGEXP_REPLACE sql function (I'm targeting Postgres), but after quick inspection of DSL class in JOOQ it seems that it is not exposed yet.

How should I approach the problem of adding new function?

  • I can try extending AbstractFunction, similarly to org.jooq.impl.Replace
  • Is there any more general way to calling functions not exposed by JOOQ's DSL?
like image 557
Lesiak Avatar asked Nov 17 '25 08:11

Lesiak


1 Answers

The REGEXP_REPLACE function has been supported since jOOQ 3.14. In older versions of jOOQ, as always when you're missing out on functionality, use plain SQL templating

public static Field<String> regexpReplace(
    Field<String> in, String pattern, String replacement
) {
    return DSL.field(
        "regexp_replace({0}, {1}, {2})", in.getDataType(), 
        in, 
        DSL.val(pattern), 
        DSL.val(replacement)
    );
}
like image 73
Lukas Eder Avatar answered Nov 20 '25 00:11

Lukas Eder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!