Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aSzl6-0007gS-DU for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Feb 2016 04:18:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aSzl6-0001ok-0G for pgsql-bugs@arkaria.postgresql.org; Tue, 09 Feb 2016 04:18:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aSzkS-0000ki-LE for pgsql-bugs@postgresql.org; Tue, 09 Feb 2016 04:17:56 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aSzkQ-0005zq-DA for pgsql-bugs@postgresql.org; Tue, 09 Feb 2016 04:17:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u194HqU1019845; Mon, 8 Feb 2016 23:17:52 -0500 From: Tom Lane To: "David G. Johnston" cc: "tarasbob@gmail.com" , "pgsql-bugs@postgresql.org" Subject: Re: BUG #13918: Simple query with Having clause returns incorrect results In-reply-to: References: <20160204221323.2780.14702@wrigleys.postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Mon, 08 Feb 2016 19:45:56 -0700" Date: Mon, 08 Feb 2016 23:17:52 -0500 Message-ID: <19844.1454991472@sss.pgh.pa.us> X-Pg-Spam-Score: -2.2 (--) 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 "David G. Johnston" writes: > On Thursday, February 4, 2016, wrote: >> The following query incorrectly returns 1 row instead of 0: >> >> SELECT 1 >> FROM some_table >> WHERE FALSE >> HAVING TRUE > So, amazingly (to me), this behavior is documented. >> The presence of HAVING turns a query into a grouped query even if there is >> no GROUP BY clause. ... Such a >> query will emit a single row if the HAVING condition is true, zero rows if >> it is not true. Yeah. This is a pretty weird corner case, but the behavior is required by SQL spec. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs