Why does IntelliJ recommends using DECODE instead of CASE in SQL queries?

Answered

In a query with column defined as so:

I get this warning:

It's notorious the fact that `DECODE` is terrible for readability. This one is kind of fine, but if you have a lot of branches, it's almost impossible to know what is what or if there is an else or not, and `CASE` is immediately recognisable by developers without SQL knowledge trying to debug some issue

The only real reason in favour of `DECODE` in my opinion is when you need to test `NULL`, as the `CASE` in the format used in the screenshot can't deal with that...

So, just being curious here... What's the reasoning for recommending `DECODE` instead of `CASE`? Maybe I'm missing something and start using `DECODE` more

Thanks

0
5 comments

Hi Guilherme,

The answer is pretty straightforward: the DECODE function requires less code to write compared to CASE operator. 

If your coding preference is in favor of CASE, you may change this behavior here:

1

Well, less code not always result in better code.

Thanks for showing where the inspection sets that for turning off.

0

Oh no... that's a project setting and not an IDE wide setting... I deal with literal dozens of repositories as a code reviewer...

Is it possible in any way to make project settings spread to all projects? That will save me some time not only on this settings, but others as well

0

Guilherme Taffarel Bergamin Please select Stored in IDE from the drop-down

This should populate the inspection settings across all projects. 

1

You are amazing, Aleksandr! Thanks

0

Please sign in to leave a comment.