Re: Function returning 2 columns evaluated twice when both columns are needed
От | Gerhard Wiesinger |
---|---|
Тема | Re: Function returning 2 columns evaluated twice when both columns are needed |
Дата | |
Msg-id | alpine.LFD.2.00.0910190732140.18766@bbs.intern обсуждение исходный текст |
Ответ на | Re: Function returning 2 columns evaluated twice when both columns are needed (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: Function returning 2 columns evaluated twice when both columns are needed
|
Список | pgsql-general |
On Sun, 18 Oct 2009, Tom Lane wrote: > Gerhard Wiesinger <lists@wiesinger.com> writes: >> 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? > > You need a sub-select, along the lines of > > SELECT > cur_date, > (gs).sum_m1, > (gs).sum_m2 > FROM > ( > SELECT > cur_date, > getSums(start_ts, stop_ts) AS gs > FROM > getDatesTimestamps($1, $2) > OFFSET 0 > ) AS ss > ; > > The OFFSET bit is a kluge, but is needed to keep the planner from > flattening the subquery and undoing your work. > Thnx Tom. It also works without the OFFSET kludge. Any ideas why? Looks also reasonable to me because there is no SETOF returned. BTW: Why is the function in the original statement evaluated twice? On "SELECT table.*" I guess query is also executed once and not n times (for each column). PG is version 8.3.8. Thnx. Ciao, Gerhard
В списке pgsql-general по дате отправления: