Search Postgresql Archives

Function returning 2 columns evaluated twice when both columns are needed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux