Function returning 2 columns evaluated twice when both columns are needed

Поиск
Список
Период
Сортировка
От Gerhard Wiesinger
Тема Function returning 2 columns evaluated twice when both columns are needed
Дата
Msg-id alpine.LFD.2.00.0910182157050.9960@bbs.intern
обсуждение исходный текст
Ответы Re: Function returning 2 columns evaluated twice when both columns are needed
Список pgsql-general
Hello,

I'm having a problem with the following:
CREATE TYPE Sums AS (sum_m1 double precision, sum_m2 double precision);
CREATE TYPE date_m1_m2 AS (cur_date date, sum_m1 double precision, sum_m2 double precision);


CREATE OR REPLACE FUNCTION getSums(IN start_ts timestamp with time
zone, IN stop_ts timestamp with time zone) RETURNS Sums AS $$
...

CREATE OR REPLACE FUNCTION getsumInterval(date, date) RETURNS SETOF date_m1_m2 AS $$
   SELECT
     cur_date,
     (getSums(start_ts, stop_ts)).* -- No optimal since function is evaluated 2 times => 24s
     -- getSums(start_ts, stop_ts) -- in one column and not usable as I need 2 columns, but takes only 12s
   FROM
     getDatesTimestamps($1, $2)
   ;
$$ LANGUAGE SQL;

Since getSums() is a cursor and is complex and takes long time getSums
should only be evaluated once. Is there a better solution available to
get both columns from the function in the select?

Thnx.

Ciao,
Gerhard

--
http://www.wiesinger.com/

В списке pgsql-general по дате отправления:

Предыдущее
От: Simon Riggs
Дата:
Сообщение: Re: Delete fails with out of memory
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Function returning 2 columns evaluated twice when both columns are needed