diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 7e5bcd9..7f04e504 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -11254,6 +11254,25 @@ SELECT NULLIF(value, '(none)') ... all are NULL. + + + Implementation Notes + + When a conditional expression depends on the results of aggregate + functions in a SELECT or HAVING clause, then all + the aggregate functions are always evaluated prior to determining which + branch the conditional should take. For example, the following query can + cause a division-by-zero error despite only using division in a branch + that requires positive values: + + +SELECT CASE WHEN min(employees) > 0 + THEN average(expenses / employees) + END + FROM departments; + + +