pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: andrea@lombardoni.ch
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8237: CASE Expression - Order of expression processing
Date: Wed, 19 Jun 2013 09:37:32 +0200
Message-ID: <20130619073732.GD19539@alap2.anarazel.de> (raw)
In-Reply-To: <10821.1371612644@sss.pgh.pa.us>
References: <E1Uovmc-0007FT-R4@wrigleys.postgresql.org>
	<20130618133132.GG5646@awork2.anarazel.de>
	<10821.1371612644@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 2013-06-18 23:30:44 -0400, Tom Lane wrote:
> Andres Freund <andres@2ndquadrant.com> writes:
> > On 2013-06-18 13:17:14 +0000, andrea@lombardoni.ch wrote:
> >> template1=# SELECT CASE WHEN (SELECT 0)=0 THEN 0 ELSE 1/0 END;
> >> ERROR:  division by zero
> 
> > Hrmpf. This is rather annoying.
> 
> Annoying, maybe.  Bug, no.  The manual is pretty clear that you don't
> have a lot of control over order of evaluation of subexpressions.

For normal clauses I absolutely grant you that. But for CASE? We've
always argued that to be escape hatch when you need to force an
order. And indeed
http://www.postgresql.org/docs/current/static/sql-expressions.html#SYNTAX-EXPRESS-EVAL
has the following example:
"But this is safe:
SELECT ... WHERE CASE WHEN x > 0 THEN y/x > 1.5 ELSE false END;"

If the WHEN clause is independent from the arithmetic expression and the
vars were replaced by, say query parameters, this will even crash.

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)

Message-ID: <20130619073732.GD19539@alap2.anarazel.de>
Permalink:  ../20130619073732.GD19539@alap2.anarazel.de/
Also on:    postgresql.org/message-id/20130619073732.GD19539@alap2.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, tgl@sss.pgh.pa.us, andrea@lombardoni.ch
  Subject: Re: BUG #8237: CASE Expression - Order of expression processing
  In-Reply-To: <20130619073732.GD19539@alap2.anarazel.de>
  References: <E1Uovmc-0007FT-R4@wrigleys.postgresql.org> <20130618133132.GG5646@awork2.anarazel.de> <10821.1371612644@sss.pgh.pa.us> <20130619073732.GD19539@alap2.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