Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id BE3246327E2 for ; Mon, 19 Oct 2009 18:54:26 -0300 (ADT) 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 92764-09 for ; Mon, 19 Oct 2009 21:54:10 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-qy0-f203.google.com (mail-qy0-f203.google.com [209.85.221.203]) by mail.postgresql.org (Postfix) with ESMTP id 7E77B633089 for ; Mon, 19 Oct 2009 18:54:15 -0300 (ADT) Received: by qyk42 with SMTP id 42so3885831qyk.28 for ; Mon, 19 Oct 2009 14:54:14 -0700 (PDT) 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 :content-transfer-encoding; bh=5QdetQhsTP8M+yXhyTodSglpZhpWZaQ5DmojGzKMuXA=; b=gwL26HHS0G7g0jbsofmsiybdMNSjv0rEBqFaGDDrTFXA/uxoksLhqL4eMwj33DK6oB R8h2GhDB9mP757rG4EhLvpSSnX3qeMHcBjB72uE6ytQgVnEPb4YZvdBH4suU32EtmKbW K4QN5syJu7EuXSLtDEQU/YYJ8gIKZJo3IkCTU= 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:content-transfer-encoding; b=h+Tq2uVXIRpJ3hWAWLfnCrPnKLpmsjL91KlAOfisCN/X+f5lRg5PeYxplvz3WWsVf2 hzWOpcGMCaMbBk8C9tqz5Xm2+SZ69MDOzb7nycvq2IYtJdtBdYerJKSsbvSYEPo0ekWK s4pvtnrDsmtPDJma5zDdgAHV/PyxFndSRfBvg= MIME-Version: 1.0 Received: by 10.229.68.30 with SMTP id t30mr767300qci.97.1255989253916; Mon, 19 Oct 2009 14:54:13 -0700 (PDT) In-Reply-To: <4ADAA720.3050706@gmail.com> References: <302670f20910161927h688e13e7qd096e63e68b7ae6c@mail.gmail.com> <4AD93837.7030500@gmail.com> <4ADAA720.3050706@gmail.com> Date: Mon, 19 Oct 2009 17:54:13 -0400 Message-ID: <302670f20910191454r4faef8f7m78b5218e6e6a5788@mail.gmail.com> Subject: Re: Efficiency in Multiple Queries of Same Table in a PL/PgSQL Function From: Gary Chambers To: Rob Sargent Cc: matthias schoeneich , pgsql-sql@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.185 tagged_above=-10 required=5 tests=BAYES_40=-0.185 X-Spam-Level: X-Archive-Number: 200910/72 X-Sequence-Number: 33271 > But if I read the OP correctly the sigma are in fact used additively in e= ach > row in blah. =A0"sigma_* =3D sigma_* +" I apologize, but I omitted a CASE statement prior to each calculation of the values. The coefficients for each calculation change depending upon which case is valid. I could probably rewrite it using arrays and may, in fact, do so to eliminate the two added queries. Thank you for your input. -- Gary Chambers /* Nothing fancy and nothing Microsoft! */