Re: multiple identical calc and function in single query

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: multiple identical calc and function in single query
Date: 2009-10-29 13:41:13
Message-ID: 20091029134113.GV5407@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 29, 2009 at 12:05:54PM +0200, Sim Zacks wrote:
> 326/getdisplayconversionmultiplebypn(pnid) is in this query 6 times. How
> many times is it evaluated?

I'm pretty sure it'll evaluated multiple times. Why don't you put it
into a sub-select, it'll at least save some typing. Something like:

SELECT pnid, calc + case when ... then .. else ... end AS qty
FROM (
SELECT pnid, 326/getdisplayconversionmultiplebypn(pnid) AS calc, ...
FROM ...) x;

I have a feeling that it may still get evaluated several times in
certain cases, but you could put a "RAISE NOTICE" into your code to
figure out.

--
Sam http://samason.me.uk/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Chiaramello 2009-10-29 16:31:47 Re: [Newbie] UPDATE based on other table content
Previous Message Thom Brown 2009-10-29 13:31:42 Re: [Newbie] UPDATE based on other table content