Re: multiple identical calc and function in single query

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: multiple identical calc and function in single query
Дата
Msg-id 20091029134113.GV5407@samason.me.uk
обсуждение исходный текст
Ответ на multiple identical calc and function in single query  (Sim Zacks <sim@compulab.co.il>)
Список 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 по дате отправления:

Предыдущее
От: Thom Brown
Дата:
Сообщение: Re: [Newbie] UPDATE based on other table content
Следующее
От: Daniel Chiaramello
Дата:
Сообщение: Re: [Newbie] UPDATE based on other table content