I observed the following behaviour (I tested the following statements in 9.0.4, 9.0.5 and 9.3beta1):
$ psql template1
template1=# SELECT CASE WHEN 0=0 THEN 0 ELSE 1/0 END;
case
------
0
(1 row)
template1=# SELECT CASE WHEN 1=0 THEN 0 ELSE 1/0 END;
ERROR: division by zero
In this case the CASE behaves as expected.
But in the following expression:
template1=# SELECT CASE WHEN (SELECT 0)=0 THEN 0 ELSE 1/0 END;
ERROR: division by zero
(Just to be sure, a "SELECT (SELECT 0)=0;" returns true)
It seems that when the "CASE WHEN expression" is a query, the evaluation order changes.
According to the documentation, this behaviour is wrong.