Postgresql Explain Nested If Else Statement