Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 993FB632F3C for ; Tue, 22 Dec 2009 10:03:58 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 16547-06 for ; Tue, 22 Dec 2009 14:03:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.wmmi.net (aleph.wmmi.net [72.14.190.87]) by mail.postgresql.org (Postfix) with ESMTP id 2C8506322F3 for ; Tue, 22 Dec 2009 10:03:51 -0400 (AST) Received: from [192.168.1.252] (mail.mormail.com [216.120.174.227]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: awilliam) by mail.wmmi.net (Postfix) with ESMTP id 60A9B1043E for ; Tue, 22 Dec 2009 09:03:49 -0500 (EST) Subject: Re: short-cutting if sum()>constant From: Adam Tauno Williams To: pgsql-sql@postgresql.org In-Reply-To: <20091222133527.3007bd96@dawn.webthatworks.it> References: <20091222133527.3007bd96@dawn.webthatworks.it> Content-Type: text/plain; charset="UTF-8" Date: Tue, 22 Dec 2009 09:02:37 -0500 Message-Id: <1261490557.6467.0.camel@linux-m3mt> Mime-Version: 1.0 X-Mailer: Evolution 2.28.0 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200912/58 X-Sequence-Number: 33496 On Tue, 2009-12-22 at 13:35 +0100, Ivan Sergio Borgonovo wrote: > Hi, > I'd like to know if > select sum(qty) from t where status=37; > is > constant. > qty is always >0. > Is there a way to skip examining further rows and return a result > ASAP? SELECT SUM(object_version) FROM date_x WHERE owner_id = 10100 HAVING SUM(object_version) > 1000 ? -- OpenGroupware developer: awilliam@whitemice.org OpenGroupare & Cyrus IMAPd documenation @