Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UpCxU-0000xf-Sp for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Jun 2013 07:37:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1UpCxU-0001am-Cj for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Jun 2013 07:37:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UpCxT-0001ag-Q8 for pgsql-bugs@postgresql.org; Wed, 19 Jun 2013 07:37:35 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UpCxR-00069b-P7 for pgsql-bugs@postgresql.org; Wed, 19 Jun 2013 07:37:35 +0000 Received: from intern.anarazel.de (p5DDC573C.dip0.t-ipconnect.de [93.220.87.60]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 2A4304E8007; Wed, 19 Jun 2013 09:37:32 +0200 (CEST) Date: Wed, 19 Jun 2013 09:37:32 +0200 From: Andres Freund To: Tom Lane Cc: andrea@lombardoni.ch, pgsql-bugs@postgresql.org Subject: Re: BUG #8237: CASE Expression - Order of expression processing Message-ID: <20130619073732.GD19539@alap2.anarazel.de> References: <20130618133132.GG5646@awork2.anarazel.de> <10821.1371612644@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <10821.1371612644@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 2013-06-18 23:30:44 -0400, Tom Lane wrote: > Andres Freund 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