Re: Function returning 2 columns evaluated twice when both columns are needed
В списке pgsql-general по дате отправления:
| От | Tom Lane |
|---|---|
| Тема | Re: Function returning 2 columns evaluated twice when both columns are needed |
| Дата | |
| Msg-id | 10515.1255899603@sss.pgh.pa.us обсуждение |
| Ответ на | Function returning 2 columns evaluated twice when both columns are needed (Gerhard Wiesinger <lists@wiesinger.com>) |
| Ответы |
Re: Function returning 2 columns evaluated twice when both
columns are needed
|
| Список | pgsql-general |
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.
regards, tom lane
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера