New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MySQL Dialect Doesn't Support NULLIF #11
Comments
You cannot pass a condition to Factory.nullIf(). As specified in the MySQL docs, both arguments have to be expressions (i.e. org.jooq.Field, or T, which is any value that can be passed to Factory.val()). In jOOQ, a condition is not an expression/field How are you calling nullif() ? Maybe it would make sense to extend jOOQ in a way to allow org.jooq.Condition to be used as a Field across the API? |
Ah ok, that must be why. Yes, being able to "cast" Conditions as a Field would be handy! |
OK, that idea will be tracked as: It might mean substantial change, as a lot of new integration tests would be needed, so I can't promise when this will be done. Cheers |
Ok sure. My work-around was to simply drop down to raw SQL, which wasn't too bad. This often comes up when you want to count rows that match a certain condition. COUNT(NULLIF([condition], false)) is a handy way to do so, but maybe I could use a case(?) |
Yes, a CASE expression would be the most SQL-like style: SUM(CASE WHEN [condition] THEN 1 ELSE 0 END) I tend to feel that the NULLIF construct is a bit less readable. But I'm not so used to MySQL, so maybe it's common practice there? Still, it's a good use case for #1178 |
Oh yeah, not sure why I didn't do it that way -- I'll try it out tomorrow. |
Worked great of course. Cheers! |
Glad it works! I allowed myself to cite your nice feedback from Stack Overflow directly on my blog, if that is OK with you? |
Sure, feel free to use the second comment too. I've been meaning to write a more thorough testimonial if that would be useful. |
Yes, any success story (e.g. on your personal / company blog) is very welcome! If you have the time, I'd be interested in a more detailed pro / con comparison between jOOQ / iBATIS for your specific use case. Such a comparison could be a base for further discussion and feature requests in jOOQ... Cheers |
Attempting to use nullif from a subtype of MySQLFactory causes an exception like the one below:
MySQL supports NULLIF as documented here:
http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_nullif
The text was updated successfully, but these errors were encountered: