-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Adding basic support for IF conditions in SELECT clause #535
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
Conversation
Adding support for IF conditions in SELECT clause. Example: SELECT IF(a = 5, 200, 404), columnA, columnB from table. Supporting different condition types for the first argument - LIKE, AND / OR, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx for splitting. It makes reviewing much easier. Wouldn't it be a much more general approach to allow conditions as parameters for functions? Then the IfExpression class would be obsolete.
@wumpz, sure, I'm happy to contribute to this great project as much as I can. If you were referring to the option of considering the "IF" as a function with 2 to 3 parameters, then I'm not sure this will be the best path here, as it might cause a big pain in the future, as it's not really a function. Also, having a dedicated class (IfExpression) allows to 'visit' the instances easily, same as with CASE / WHEN conditions and other special structures. Looking forward to hearing your thoughts. |
Looking at http://sqlfiddle.com/#!17/cc4c9/1/0 you see, that using e.g. Postgresql you are able to use a relation as a normal parameter: |
Can't see which function call are you referring to. The query in that fiddle is: |
Sorry for beeing unclear. In Postgresql it would be perfectly valid to write a function that processes myfunc(mycol = 'A'), indeed every function with a boolean parameter could receive this as a parameter. This is a whole class of functions (including this kind of parameter) JSqlParser is not able to parse. Hope that was clearer. |
Thanks for the clarification. |
@wumpz, did you get a chance to look into my last comment? Will be glad to see this change pulled in case you agree. |
@sh-tomer If you referring about syntactical correctness for one database, I think you are right. Nevertheless I see JSqlParser as a parser and not a validator of specific database constructs. So you could write using Postgresql a function if with one parameter and could go with this relational parameter |
Adding support for IF conditions in SELECT clause.
Example: SELECT IF(a = 5, 200, 404), columnA, columnB from table.
Supporting different condition types for the first argument - LIKE, AND / OR, etc.