This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.
Unreachable CASE clauses
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
When a searched CASE expression contains unreachable WHEN
or ELSE
clauses, we can remove them.
Using Settings.transformPatternsUnreachableCaseClauses
, the following transformations can be achieved:
-- With Settings.transformPatternsUnreachableCaseClauses active, this: SELECT CASE WHEN a = b THEN 1 WHEN TRUE THEN 2 WHEN c = d THEN 3 END, CASE WHEN a = b THEN 1 WHEN FALSE THEN 2 WHEN c = d THEN 3 END FROM tab; -- ... is transformed into the equivalent expression: SELECT CASE WHEN a = b THEN 1 ELSE 2 END, CASE WHEN a = b THEN 1 WHEN c = d THEN 3 END FROM tab;
A more subtle unreachable WHEN
clause is a clause that has already been listed, irrespective of the THEN
clause. While removing it is a correct transformation, the duplicate might be likely due to a typo.
-- With Settings.transformPatternsUnreachableCaseClauses active, this: SELECT CASE WHEN a = b THEN 1 WHEN c = d THEN 2 WHEN a = b THEN 3 END FROM tab; -- ... is transformed into the equivalent expression: SELECT CASE WHEN a = b THEN 1 WHEN c = d THEN 2 END FROM tab;
Feedback
Do you have any feedback about this page? We'd love to hear it!