Re: multiple identical calc and function in single query - Mailing list pgsql-general

From Sam Mason
Subject Re: multiple identical calc and function in single query
Date
Msg-id 20091029134113.GV5407@samason.me.uk
Whole thread Raw
In response to multiple identical calc and function in single query  (Sim Zacks <sim@compulab.co.il>)
List 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/

pgsql-general by date:

Previous
From: Thom Brown
Date:
Subject: Re: [Newbie] UPDATE based on other table content
Next
From: Daniel Chiaramello
Date:
Subject: Re: [Newbie] UPDATE based on other table content