Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uow02-0001iu-MI for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Jun 2013 13:31:06 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Uow01-0000A3-O4 for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Jun 2013 13:31:05 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uovzx-0008VK-S6 for pgsql-bugs@postgresql.org; Tue, 18 Jun 2013 13:31:02 +0000 Received: from moutng.kundenserver.de ([212.227.17.10]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uovzv-0007fu-5I for pgsql-bugs@postgresql.org; Tue, 18 Jun 2013 13:31:01 +0000 Received: from anarazel.de (p5DDC5AA1.dip0.t-ipconnect.de [93.220.90.161]) by mrelayeu.kundenserver.de (node=mrbap1) with ESMTP (Nemesis) id 0LjdUG-1UI5Dl1Gx6-00cB2Q; Tue, 18 Jun 2013 15:30:57 +0200 Received: by anarazel.de (Postfix, from userid 1000) id 75ED1101751; Tue, 18 Jun 2013 15:31:32 +0200 (CEST) Date: Tue, 18 Jun 2013 15:31:32 +0200 From: Andres Freund To: andrea@lombardoni.ch Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8237: CASE Expression - Order of expression processing Message-ID: <20130618133132.GG5646@awork2.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V02:K0:fGjlihAy4BPJqRBsx2fu4SPcdLHx7Anr+oF47qY1q8l qCRovYiHvtm88SGUcqT/y/0Q3KMGxxUD9KxIMgtB0hmbobsG2K QgmYnqX5ZVElg91GvBMFv+PmnYnTbJDPN5o2z5WPqdDxciNCan yx1KYnVrUVigR2lyDcqe2Hj06wtj6fzZ3/EViKEnGqigYN1vU0 tqC3zv3aGKU/94Cp1vHzD0mQNp35B+F29hCMBa5bbbAwMq+NFv fAZQ+aTxDXFpsOLX9/b1bsTmI9Ax64eUH9Zz+jpdUdhtaWzPbe DU1fSkwsSjxfz0UsT4jh8L4ax4qX2PxKi18AL086y6eHLqBi88 tTbZRCHbX7sY0LR8H8uEQVb2HcaYXe8KGGyPLzlb+ X-Pg-Spam-Score: 0.8 (/) 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 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