pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@2ndquadrant.com>
To: andrea@lombardoni.ch
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8237: CASE Expression - Order of expression processing
Date: Tue, 18 Jun 2013 15:31:32 +0200
Message-ID: <20130618133132.GG5646@awork2.anarazel.de> (raw)
In-Reply-To: <E1Uovmc-0007FT-R4@wrigleys.postgresql.org>
References: <E1Uovmc-0007FT-R4@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (5+ messages)  latest in thread

Message-ID: <20130618133132.GG5646@awork2.anarazel.de>
Permalink:  ../20130618133132.GG5646@awork2.anarazel.de/
Also on:    postgresql.org/message-id/20130618133132.GG5646@awork2.anarazel.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: andres@2ndquadrant.com, andrea@lombardoni.ch
  Subject: Re: BUG #8237: CASE Expression - Order of expression processing
  In-Reply-To: <20130618133132.GG5646@awork2.anarazel.de>
  References: <E1Uovmc-0007FT-R4@wrigleys.postgresql.org> <20130618133132.GG5646@awork2.anarazel.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox