JOOQ not using table aliases with columns in forUpdate().Of()

68 views
Skip to first unread message

Oleg

unread,
Mar 22, 2015, 12:24:04 PM3/22/15
to jooq...@googlegroups.com
Hi 

I have select like this in Jooq 3.5.0:

...
.forUpdate()
.of(Tables.CLIENT.as("clients").NUM., Tables.ACCOUNT.as("accounts").ID)
.skipLocked()
.fetch();

The generated SQL will end with 

FOR UPDATE OF "NUM", "ID" SKIP LOCKED 

instead of 

FOR UPDATE OF "clients"."NUM", "accounts"."ID" SKIP LOCKED 


Is it possible to make JOOQ use table alias in the for update statement?

Lukas Eder

unread,
Mar 23, 2015, 3:27:04 AM3/23/15
to jooq...@googlegroups.com
Hello,

Indeed, only the unqualified column name is being rendered to the SQL output, no matter what kind of Field expression you're putting there. There must be some historic reason for this, related to a SQL dialect that doesn't support qualification in the FOR UPDATE .. OF clause - or that has only limited support for qualification. I'll need to investigate this, and I've registered an issue:

What dialect are you using? Oracle?

As a workaround, you might be able to write:

DSLContext ctx = DSL.using(configuration);

...
.of(DSL.field(ctx.render(Tables.CLIENT.as("clients").NUM)),
 DSL.field(ctx.render(Tables.CLIENT.as("clients").ID.toString())))

That would generate the SQL string first, before embedding it in the AST

Hope this helps,
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oleg

unread,
Mar 23, 2015, 10:06:57 AM3/23/15
to jooq...@googlegroups.com
Yes, it is Oracle.

By the way, is there a way to override JOOQ behavior for such situations in the future?

I expected that DSL.inline() will help and output as is, but Jooq tries to wrap it with "" anyway - it would be great if I could fix it until bug or problem is fixed.

воскресенье, 22 марта 2015 г., 19:24:04 UTC+3 пользователь Oleg написал:

Lukas Eder

unread,
Mar 23, 2015, 10:25:13 AM3/23/15
to jooq...@googlegroups.com
2015-03-23 15:06 GMT+01:00 Oleg <olkuz...@gmail.com>:
Yes, it is Oracle.

By the way, is there a way to override JOOQ behavior for such situations in the future?

In this particular case, the "dequalifying" of the column reference is hard-wired in jOOQ's internals (in org.jooq.impl.SelectQueryImpl) and cannot be overridden, although as I mentioned in my previous E-Mail, DSL.field(String) should work, as that's how you can inject "plain SQL" into jOOQ ASTs (Abstract Syntax Trees). Here's some additional info on "plain SQL" from the manual:

I expected that DSL.inline() will help and output as is, but Jooq tries to wrap it with "" anyway

DSL.inline() is used for inline bind variables / constants. If they're String constants, they have to be wrapped with apostrophes.
 
- it would be great if I could fix it until bug or problem is fixed.

We'll certainly look into this pretty soon for jOOQ 3.6.0 and probably also for 3.5.4. Do note that we deliver the sources and grant the right to modification to our customers when you purchase the jOOQ Professional Edition license as some of our customers need to be able to fix issues very quickly themselves. Let me know if you are interested in more details about our commercial licensing terms.

Looking forward to hearing from you again,
Lukas

Oleg Kuznetsov

unread,
Mar 23, 2015, 10:46:27 AM3/23/15
to jooq...@googlegroups.com
Hm, I actually tried .field(), .inline(), .value() - none of them worked out.

--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/WDAsX3ySbeQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.

Lukas Eder

unread,
Mar 23, 2015, 11:19:21 AM3/23/15
to jooq...@googlegroups.com
I'm sorry for the confusion. I should have tested my own suggestion before mailing it. Indeed, it doesn't work the way I suggested. Here's another workaround that works for me:

DSLContext ctx = DSL.using(connection, SQLDialect.ORACLE, new Settings().withRenderNameStyle(RenderNameStyle.AS_IS);

ctx.select(...)
   .from(Tables.CLIENT.as("clients"))
   .forUpdate()
   .of(DSL.field(ctx.render(Tables.CLIENT.as("clients").NUM)),
       DSL.field(ctx.render(Tables.CLIENT.as("clients").ID)))
   .fetch();

This RenderNameStyle setting will prevent the double quotes from being added around table / column identifiers. More information about Settings can be found here:

I've increased the priority of issue #4151. The current implementation is really wrong - at least for Oracle. Thanks for reporting this!

Let me know if the above helps
Lukas

--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.

Oleg Kuznetsov

unread,
Mar 23, 2015, 12:05:54 PM3/23/15
to jooq...@googlegroups.com
Thank you for quick reply!

Lukas Eder

unread,
Apr 8, 2015, 9:44:32 AM4/8/15
to jooq...@googlegroups.com
From our integration tests, I don't see any reason why we shouldn't allow for fully qualified columns in the FOR UPDATE OF clause. Obviously, there may be corner cases, but users can still use column references that don't use full qualification explicitly.

We'll implement this for jOOQ 3.6, without backporting - to prevent any unforeseen issues that may arise from a hidden corner case.
Reply all
Reply to author
Forward
0 new messages