Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 8350863326A for ; Tue, 22 Dec 2009 09:49:06 -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 14184-02 for ; Tue, 22 Dec 2009 13:48:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-bw0-f213.google.com (mail-bw0-f213.google.com [209.85.218.213]) by mail.postgresql.org (Postfix) with ESMTP id A4D8C632F3C for ; Tue, 22 Dec 2009 09:48:58 -0400 (AST) Received: by bwz5 with SMTP id 5so4144026bwz.3 for ; Tue, 22 Dec 2009 05:48:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=lLLWxFmYhOjBM4nptOU91I289eCgJVpaDpV/7ZRXBus=; b=wcWIuBxIFp8yltaujwcgKn+ReiuQpJcIuaKGurdLo5SttytWQG0HsoqvKt8BBEPLim ROywOmfFWZetthkBGBgr1iZrfNKtz0htR1Ri0IPujFnUrrczU1Xi4Gc7OnRDJjpsAvKu bReAi4ltw8MYknQSXkumoHQZEZaslnT3D5rfM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=gnfDBgAfJtNTaO+yZV9l9j06HK0Q0LcyhoOrf3jQitg9MhA5E1pBKBQCdzaN5HoUVr Rv8Wp0vudZedW4DRkXp8rh1mda8RcnffEhw7UkpxUvpb2/cBIwSfWe61tbE3TWScfq3j VbG5/FQCaxPVqbVM0mO6amxOQR5Xex4b6iAXE= MIME-Version: 1.0 Received: by 10.204.16.88 with SMTP id n24mr5588607bka.52.1261489735910; Tue, 22 Dec 2009 05:48:55 -0800 (PST) In-Reply-To: <20091222133527.3007bd96@dawn.webthatworks.it> References: <20091222133527.3007bd96@dawn.webthatworks.it> Date: Tue, 22 Dec 2009 14:48:55 +0100 Message-ID: <92869e660912220548j43a4528fu28b1389477e9fb1c@mail.gmail.com> Subject: Re: short-cutting if sum()>constant From: =?UTF-8?Q?Filip_Rembia=C5=82kowski?= To: Ivan Sergio Borgonovo Cc: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=0003255597fe98c595047b5177a8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.598 tagged_above=-10 required=5 tests=BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200912/57 X-Sequence-Number: 33495 --0003255597fe98c595047b5177a8 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2009/12/22 Ivan Sergio Borgonovo > Hi, > Hi :-) > > I'd like to know if > > select sum(qty) from t where status=3D37; > > is > constant. > > qty is always >0. > > Is there a way to skip examining further rows and return a result > ASAP? > With plain SQL, no. With a user defined function in PL/PgSQL, yes. > > > -- > Ivan Sergio Borgonovo > http://www.webthatworks.it > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > --=20 Filip Rembia=C5=82kowski JID,mailto:filip.rembialkowski@gmail.com http://filip.rembialkowski.net/ --0003255597fe98c595047b5177a8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

2009/12/22 Ivan Sergio Borgonovo <mail@webthatworks.it= >
Hi,

Hi :-)
=C2=A0

I'd like to know if

select sum(qty) from t where status=3D37;

is > constant.

qty is always >0.

Is there a way to skip examining further rows and return a result
ASAP?


With plain SQL, no= .

With a user defined function in PL/PgSQL, yes.

=C2=A0


--
Ivan Sergio Borgonovo
http://www.webthat= works.it


--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
= http://www.postgresql.org/mailpref/pgsql-sql



--
Filip Rembia=C5= =82kowski
JID,mailto:fi= lip.rembialkowski@gmail.com
http://filip.rembialkowski.net/
--0003255597fe98c595047b5177a8--