Generate sql statements with flyway placeholders

226 Views Asked by At

I trying to save some sql insert statements to files to use them for testing. I would like to use flyway placeholders for that but I'm not able to find any.

Some example in Java:

var sqlTXT = sql.insertInto(table("TBLNAME"))
     .set(field("strCol"), field("strVal").toString())
     .set(field("placeHolderCol"), field(inline("${flyway:user}")))
     .getSQL(ParamType.INLINED);

This will produce SQL string like this one:

insert into TBLNAME (strCol, placeHolderCol) values ('strVal', '${flyway:user}')

and I'm looking for something like this

insert into TBLNAME (strCol, placeHolderCol) values ('strVal', ${flyway:user})

So flyway can substitute ${flyway:user} and insert user name.

Is there any way to render sql like this or will I have to do it "manually"?

1

There are 1 best solutions below

0
Lukas Eder On BEST ANSWER

Flyway's placeholders are no different from any other "vendor specific" SQL syntax, which isn't supported out of the box by jOOQ, so plain SQL templating has the answer.

Just use

field("${flyway:user}")

Don't use DSL.inline(), which is used for creating "inline values" (e.g. a string literal).