JSqlParser
JSqlParser copied to clipboard
Error when parsing switch expressions with OR or AND.
Describe the bug
First things first: thank you for your work!
A switch expression of a CASE, if containing a OR or a AND, makes the parsing crash.
To Reproduce
SELECT true AND false;
and
SELECT true OR false;
work fine
SELECT CASE true | false
WHEN true THEN 1
ELSE 2
END
and
SELECT CASE true & false
WHEN true THEN 1
ELSE 2
END
also have the expected behaviour (with a bitwise expression being returned as the switch expression).
But
SELECT CASE true AND false
WHEN true THEN 1
ELSE 2
END;
raises an exception:
Encountered unexpected token: "AND" "AND"
(the issue is similar when AND is replaced by OR).
Expected behavior The last statement should be successfully parsed, with a AndExpression/OrExpression used as the switch expression. At least, https://www.w3schools.com accepts it, and Datagrip sends this kind of statement on Postgres databases.
System
- Database you are using: my own, mimicking PostreSQL.
- Java Version: java 12.0.2
- JSqlParser version: 4.3
Confirmed. JSqlParser only allows there a condition. Within the where more complex expressions are allowed:
case when a and b then .. end
In the when, an Expression is required, while case switches only allow a Condition.
Should I submit a pull request that replaces the Condition with an Expression? By doing so, all the test I proposed in https://github.com/JSQLParser/JSqlParser/pull/1459 do pass.
Sorry for the delay. Sure you could provide a PR. But be aware that the performance could degrade.
Closed, since no further question has been asked.