Re: CASE Statement - Order of expression processing

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "andrea(at)lombardoni(dot)ch" <andrea(at)lombardoni(dot)ch>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: CASE Statement - Order of expression processing
Date: 2013-06-18 07:39:49
Message-ID: A737B7A37273E048B164557ADEF4A58B17BB3B00@ntex2010a.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andrea Lombardoni wrote:
> It gets even stranger:
>
> template1=# SELECT CASE WHEN (SELECT 0)=0 THEN 0 ELSE 1/(select 0) END;
> case
> ------
> 0
> (1 row)
>
> Here it seems that the ELSE does not get evaluated (which is correct).

Yes, of course, because both subselects will not get evaluated at
planning time.

The problem occurs only if one of the branches gets evaluated at plan time
but the condition doesn't.

Yours,
Laurenz Albe

In response to

Browse pgsql-general by date

  From Date Subject
Next Message sachin kotwal 2013-06-18 08:52:58 Migration from DB2 to PostgreSQL
Previous Message Albe Laurenz 2013-06-18 07:37:52 Re: JDBC prepared statement is not treated as prepared statement