Reputation: 1852
I'm using jOOQ to generate PlainSQL queries, that mostly follow ANSI SQL.
What if I'm dealing with a SQL statement for a field, that needs to be parsed to verify if it's correct SQL (I'm using DSL.using(SQLDialect.DEFAULT).parser().parseField(sqlString)
), but the resulting sql from this field should use the platform native syntax and keywords?
Consider an example SQL statement for a field TO_HEX(SHA256(CAST(userId AS string)))
(note that I've set the DSLContext
to ignore unknown functions).
When parsing this using parseField
and inspecting the resulting SQL, this is transformed into to_hex(SHA256(cast(userId as varchar)))
. The target platform however, does not support varchar
. Is there any option to specify how e.g. a cast like this should be rendered? I've looked into the documentation, but I can't seem to find how to override specific keywords / define my own dialect.
Upvotes: 3
Views: 136
Reputation: 221155
There are 2 dialects you should configure:
DSL.using()
(corresponding to Configuration.dialect()
) is the output dialect, i.e. you should set that to your target dialectSettings.parseDialect
is the input dialect. If your dialect isn't supported, you can leave this untouched.If you need to support custom syntax in the parser, there's a ParseListener
SPI, which allows for overriding input/output behaviour for certain syntax elements. You can't use this to override everything, but it should work at least for:
Field
expressionsCondition
expressionsTable
expressionsUpvotes: 2