1) Converting mysql If, then clause for a field to jooq select 2) Late bind?

776 views
Skip to first unread message

Aram Mirzadeh

unread,
Nov 20, 2013, 7:54:23 PM11/20/13
to jooq...@googlegroups.com
Hi, 

Can someone point me toward how to conver this select to JOOQ?

SELECT 
     `foo`,
     IF(`d_fk` > 0, 'Yes', 'No') AS 'Active',
     `bar`
FROM TABLEA 

TABLE_A has gone through the code generation. 

Result<?> result = context.select().TABLEA.FOO,????, TABLEA.BAR).fetch(); 

Also I have a SQL statement that is expecting a bind so it's: 

SELECT `foo` FROM TABLEB WHERE id=?

How do I bind a var, and execute this query?  Should I rewrite this as a JOOQ select (it's very very long and complex, and it only only has the one bind variable).

Thanks.

Lukas Eder

unread,
Nov 21, 2013, 3:52:30 AM11/21/13
to jooq...@googlegroups.com
Hi Aram,

2013/11/21 Aram Mirzadeh <a...@tranquilphotos.com>

Hi, 

Can someone point me toward how to conver this select to JOOQ?

SELECT 
     `foo`,
     IF(`d_fk` > 0, 'Yes', 'No') AS 'Active',
     `bar`
FROM TABLEA 

TABLE_A has gone through the code generation. 

Result<?> result = context.select().TABLEA.FOO,????, TABLEA.BAR).fetch(); 

MySQL's IF function is currently not explicitly supported by jOOQ. You can either resort to plain SQL. An example is given here:

Or you use a CASE expression instead:
 
Also I have a SQL statement that is expecting a bind so it's: 

SELECT `foo` FROM TABLEB WHERE id=?

How do I bind a var, and execute this query?  Should I rewrite this as a JOOQ select (it's very very long and complex, and it only only has the one bind variable).

Please consider the manual's section about bind values, and its subsections:

By default, all values passed to jOOQ are rendered as bind values on a JDBC PreparedStatement, unless you explicitly use DSL.inline():

Aram Mirzadeh

unread,
Nov 21, 2013, 9:38:46 AM11/21/13
to jooq...@googlegroups.com

Thank you very much. 

Aram

david....@gmail.com

unread,
Sep 12, 2016, 2:52:13 PM9/12/16
to jOOQ User Group
Hi Lukas,

Is the if feature supported now? If so, since which major version?

Thanks,
Wei

Lukas Eder

unread,
Sep 12, 2016, 3:05:56 PM9/12/16
to jooq...@googlegroups.com
Hi Wei,

No, we currently have no plans of supporting "IF". The main reason is that we can't call the method "if" in Java, which is a reserved word. Using any other word might make it tricky for a user to find the method.

If you have any suggestions, please do let us know. Rest assured that the mentioned workarounds still work, though.

Cheers,
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kush...@centilytics.com

unread,
Aug 22, 2018, 3:56:42 AM8/22/18
to jOOQ User Group
Any updates on it now??


On Tuesday, September 13, 2016 at 12:35:56 AM UTC+5:30, Lukas Eder wrote:
Hi Wei,

No, we currently have no plans of supporting "IF". The main reason is that we can't call the method "if" in Java, which is a reserved word. Using any other word might make it tricky for a user to find the method.

If you have any suggestions, please do let us know. Rest assured that the mentioned workarounds still work, though.

Cheers,
Lukas
2016-09-12 20:50 GMT+02:00 <david....@gmail.com>:
Hi Lukas,

Is the if feature supported now? If so, since which major version?

Thanks,
Wei

--
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.

Lukas Eder

unread,
Aug 22, 2018, 4:00:37 AM8/22/18
to jooq...@googlegroups.com
Thank you very much for taking the time to comment. No, there are no updates on this. Please do look at the workarounds exposed in this discussion.

Thanks,
Lukas

Lukas Eder

unread,
May 6, 2020, 3:02:18 AM5/6/20
to jOOQ User Group
For the record: There is now a pending feature request which will ship with jOOQ 3.14:

We now have a thorough strategy how to work with Java keyword collisions, having already added support for the IF statement in the procedural APIs:

The strategy is to append an underscore and call the function if_()
Thanks,
Lukas

To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+unsubscribe@googlegroups.com.

Lukas Eder

unread,
May 6, 2020, 3:25:13 AM5/6/20
to jOOQ User Group
I've just noticed, we already had the IIF() function from SQL Server for a while, although it produced a CASE expression on MySQL, not the IF() function.

To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/46ab1125-b18f-4b31-a3d6-b9016d767ba8%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages