Re: [BUGS] BUG #11661: CASE ELSE is evaluated although condition is true

Поиск
Список
Период
Сортировка
От Marti Raudsepp
Тема Re: [BUGS] BUG #11661: CASE ELSE is evaluated although condition is true
Дата
Msg-id CABRT9RDMWvoAW-NASCvO08AMZqED5N0jytYHPsoeor=O0VdmMg@mail.gmail.com
обсуждение исходный текст
Ответы Re: [BUGS] BUG #11661: CASE ELSE is evaluated although condition is true  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-docs
On Mon, Oct 13, 2014 at 2:05 PM,  <michael@aplaypowered.com> wrote:
> case when sum( column1 ) = 0
>             then 0
>             else round( sum(   price
>                              * hours
>                              / column1 ), 2 )

> I would expect that the else part would never be evaluated.
> Documentation only describes that this happens for immediates.

I explained this behavior in the Stack Overflow answer, it is caused
by way aggregates are evaluated in a SELECT (or HAVING) clause.

Our documentation should be clearer about the fact that all aggregates
are evaluated strictly before their surrounding SELECT expressions,
the attached documentation patch adds a note about this to the
"general processing of SELECT" explanation.

I also created a section "Implementation Notes" in the "Conditional
Expressions" chapter to explain this behavior, since conditionals is
where this behavior is most visible.

This similarly affects the HAVING clause:
db=# select sum(1/i) from unnest(array[0])i having min(i)>0;
ERROR:  division by zero

Regards,
Marti

Вложения

В списке pgsql-docs по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Huge pages section needs to describe hugetlb_shm_group, memlock limit
Следующее
От: Josh Kupershmidt
Дата:
Сообщение: Re: Documentation for CREATE USER