Add support for expressions in case#938
Add support for expressions in case#938tomershay wants to merge 2 commits intoJSQLParser:masterfrom tomershay:add_support_for_expressions_in_case
Conversation
|
This expression right after case is supported a while. Your test sql is parsed using an unmodified JSqlParser V3.2-SNAPSHOT:
So maybe you had another problem? Here are the issues, that solved and extended your kind of syntax: at least the older one is from dec 2016. |
|
Maybe I'm missing something, but I just built the latest master from source, and the following test fails: The error: |
|
It seems that the source code might indicate the problem: From what I understand, the expression-after-case is currently supported when it has a simple expression following it (handled by WhenThenValue). |
|
That is right. switchExp represents exactly the expression after CASE. Strangely enough, here I am not anymore able to parse your test statement, but I have no actual sources at hand. Maybe some of my last not yet pushed changes did have this effect. I have to look into this. |
|
Thanks for the update. Please let me know if a fix for this is coming up in your internal changes. If not, let me know what you think we should change in this PR to make it valuable and approvable. |
|
I don't know what I saw :(. Now it fails here as well. However, I changed it to accept your case as well. Indeed the whole case parsing was simplified because there is no more difference between both cases. Just wait a bit. I have another issue to close. JSqlParser here would fail some tests and I do not yet want to push this version. |
|
I just deployed a new version. Could you check it? |
|
@wumpz, just tested it and it works great! |
MySQL supports expressions in CASE statements before the WHEN clause.
Example:
CASE <expr> WHEN ....The expression after the CASE keyword is optional.
This PR adds support for such expressions, in case they exist in the query.
Relevant docs for both options: https://dev.mysql.com/doc/refman/5.7/en/case.html