Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 4E8486335DB for ; Tue, 22 Dec 2009 13:23:02 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 34068-10 for ; Tue, 22 Dec 2009 17:22:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp-out13.alice.it (smtp-out13.alice.it [85.33.2.18]) by mail.postgresql.org (Postfix) with ESMTP id 6FC21633762 for ; Tue, 22 Dec 2009 13:22:49 -0400 (AST) Received: from FBCMMO03.fbc.local ([192.168.68.197]) by smtp-out13.alice.it with Microsoft SMTPSVC(6.0.3790.3959); Tue, 22 Dec 2009 18:20:10 +0100 Received: from FBCMCL01B01.fbc.local ([192.168.69.82]) by FBCMMO03.fbc.local with Microsoft SMTPSVC(6.0.3790.3959); Tue, 22 Dec 2009 18:20:07 +0100 Received: from lan.webthatworks.it ([79.0.145.79]) by FBCMCL01B01.fbc.local with Microsoft SMTPSVC(6.0.3790.3959); Tue, 22 Dec 2009 18:20:08 +0100 Received: from dawn.webthatworks.it (dawn.webthatworks.it [192.168.1.12]) by lan.webthatworks.it (Postfix) with ESMTP id 33EFE3005EF for ; Tue, 22 Dec 2009 18:20:07 +0100 (CET) Received: from dawn.webthatworks.it (localhost [127.0.0.1]) by dawn.webthatworks.it (Postfix) with ESMTP id F218E3DA9B for ; Tue, 22 Dec 2009 18:20:06 +0100 (CET) Date: Tue, 22 Dec 2009 18:20:06 +0100 From: Ivan Sergio Borgonovo Cc: pgsql-sql@postgresql.org Subject: Re: short-cutting if sum()>constant Message-ID: <20091222182006.73810ebd@dawn.webthatworks.it> In-Reply-To: <92869e660912220548j43a4528fu28b1389477e9fb1c@mail.gmail.com> References: <20091222133527.3007bd96@dawn.webthatworks.it> <92869e660912220548j43a4528fu28b1389477e9fb1c@mail.gmail.com> Organization: http://www.webthatworks.it X-Mailer: Claws Mail 3.7.3 (GTK+ 2.18.5; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-OriginalArrivalTime: 22 Dec 2009 17:20:08.0543 (UTC) FILETIME=[02B06EF0:01CA832B] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.721 tagged_above=-10 required=5 tests=AWL=-0.414, BAYES_00=-2.599, MISSING_HEADERS=1.292 X-Spam-Level: X-Archive-Number: 200912/61 X-Sequence-Number: 33499 On Tue, 22 Dec 2009 14:48:55 +0100 Filip Rembia=C5=82kowski wrote: > With plain SQL, no. >=20 > With a user defined function in PL/PgSQL, yes. thanks to all. I'm on 8.3 so no CTE. I was hoping there was some way to write it in plain SQL. I'm planning to wrap everything in a plpgsql function using cursors and then switch to WITH when I'll move to 8.4. --=20 Ivan Sergio Borgonovo http://www.webthatworks.it