Re: BUG #8237: CASE Expression - Order of expression processing - Mailing list pgsql-bugs

From Andres Freund
Subject Re: BUG #8237: CASE Expression - Order of expression processing
Date
Msg-id 20130618133132.GG5646@awork2.anarazel.de
Whole thread Raw
In response to BUG #8237: CASE Expression - Order of expression processing  (andrea@lombardoni.ch)
Responses Re: BUG #8237: CASE Expression - Order of expression processing
Re: BUG #8237: CASE Expression - Order of expression processing
List pgsql-bugs
On 2013-06-18 13:17:14 +0000, andrea@lombardoni.ch wrote:
> 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

Hrmpf. This is rather annoying. Const simplification processes all
clauses and evaluates them if it can. Which is - as demonstrated above -
broken. The only reason
#= SELECT CASE WHEN 1=1 THEN 0 ELSE 1/0 END;
works is that we abort even looking at further WHEN clauses if we know
that one WHEN succeeds.
So it seems we need to stop processing after finding a single WHEN
that's not const? Does anybody have a better idea?

Greetings,

Andres Freund

--
 Andres Freund                       http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

pgsql-bugs by date:

Previous
From: andrea@lombardoni.ch
Date:
Subject: BUG #8237: CASE Expression - Order of expression processing
Next
From: Pavel Stehule
Date:
Subject: Re: BUG #8237: CASE Expression - Order of expression processing