Re: BUG #8237: CASE Expression - Order of expression processing

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: andrea(at)lombardoni(dot)ch, pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #8237: CASE Expression - Order of expression processing
Date: 2013-06-18 13:49:06
Message-ID: CAFj8pRARD0kkZVpDWZqExRbQTXdL5WtWRvQwMHBMLqDNy05yiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

2013/6/18 Andres Freund <andres(at)2ndquadrant(dot)com>:
> On 2013-06-18 13:17:14 +0000, andrea(at)lombardoni(dot)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?

probably we should to evaluate constants under subtransaction, and
after exception, we should to stop precalculation of related
subexpression.

But it is slow :(

>
> Greetings,
>
> Andres Freund
>
> --
> Andres Freund http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message james.e.hughes 2013-06-18 15:02:52 BUG #8238: duplicate of bug #6372 on panffs
Previous Message Andres Freund 2013-06-18 13:31:32 Re: BUG #8237: CASE Expression - Order of expression processing