BUG #11661: CASE ELSE is evaluated although condition is true - Mailing list pgsql-bugs

From michael@aplaypowered.com
Subject BUG #11661: CASE ELSE is evaluated although condition is true
Date
Msg-id 20141013110542.25460.3900@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #11661: CASE ELSE is evaluated although condition is true  (Marti Raudsepp <marti@juffo.org>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      11661
Logged by:          Michael Stieler
Email address:      michael@aplaypowered.com
PostgreSQL version: 9.2.6
Operating system:   RHEL
Description:

I am not sure if it is a bug, a lack in documentation or just a
misunderstanding.
This issue refers to a StackOverflow question at

https://stackoverflow.com/questions/26297035/posgtres-case-condition-with-sum-aggregation-evaluates-not-needed-else-part

The following query:
case when sum( column1 ) = 0
            then 0
            else round( sum(   price
                             * hours
                             / column1 ), 2 )
raises a division by zero error, although the condition sum(column1) = 0 is
true. I would expect that the else part would never be evaluated.
Documentation only describes that this happens for immediates.

pgsql-bugs by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: BUG #10680: LDAP bind password leaks to log on failed authentication
Next
From: Bruce Momjian
Date:
Subject: Re: BUG #11325: Documentation Bug / RFE