Re: Count of records in a row

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: Count of records in a row
Дата
Msg-id CAHyXU0w_ftCU=hDWpF1N1oFDwVpB4U3LrAcOB0-1XiDV8NNVXw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Count of records in a row  (Rémi Cura <remi.cura@gmail.com>)
Ответы Re: Count of records in a row  (Rémi Cura <remi.cura@gmail.com>)
Список pgsql-general
On Tue, Oct 22, 2013 at 9:09 AM, Rémi Cura <remi.cura@gmail.com> wrote:
>
> Thanks for this good example Merlin !
>
> I didn't know you could use variable inside custom aggregates, and this
> allow to solve the problem!
>
> In my own problem I couldn't use aggregates because
> _as it output at most one row, it would have mean a lots of useless
> computation (as in this example I guess, (please correct me if it's not the
> case) :

That is not the case.  With the approach above what you 'pay' vs
standard loop is basically one pl/pgsql function call per output row.
(you can do it in straight sql, but when with pl/pgsql to leverage
cached function parsing).  What you 'get' is a more general function
because the loop structure is in the query itself as well as the
output structure.  This cleanly separates action from the data.
Usually, the mechanics of executing the aggregate are not a huge part
of query execution time.  Actually, the worst case is when the
aggregate is trivial but no matter what it's O(n).

I'm not clear what on the issue is with your particular case, since
you didn't post it :-).   Maybe post some extra detail?

merlin


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

Предыдущее
От: Rémi Cura
Дата:
Сообщение: Re: Count of records in a row
Следующее
От: Rémi Cura
Дата:
Сообщение: Re: Count of records in a row