Re: CASE Statement - Order of expression processing - Mailing list pgsql-general

From Albe Laurenz
Subject Re: CASE Statement - Order of expression processing
Date
Msg-id A737B7A37273E048B164557ADEF4A58B17BC1412@ntex2010a.host.magwien.gv.at
Whole thread Raw
In response to Re: CASE Statement - Order of expression processing  (Stefan Drees <stefan@drees.name>)
List pgsql-general
>> But in the following expression:
>>
>> template1=# SELECT CASE WHEN (SELECT 0)=0 THEN 0 ELSE 1/0 END;
>> ERROR:  division by zero
>>
>> (Just to be sure, a "SELECT (SELECT 0)=0;" returns true)
>>
>> It seems that when the "CASE WHEN expression" is a query, the evaluation
>> order changes.
>> According to the documentation, this behaviour is wrong.

Just to keep you updated:

We have updated the documentation to alert people to this behaviour:
http://www.postgresql.org/docs/devel/static/functions-conditional.html#FUNCTIONS-CASE

There were considerations to change the behaviour, but
that would mean that query execution time suffers in
many cases.  It was decided that the problem occurs only
in rather artificial queries, and that it would not be worth
changing the normally useful behaviour of constant folding
during query planning.

Yours,
Laurenz Albe

pgsql-general by date:

Previous
From: Alban Hertroys
Date:
Subject: Re: utf8 errors
Next
From: Alban Hertroys
Date:
Subject: Re: utf8 errors