Sample of user-define window function and other things
| От | Hitoshi Harada |
|---|---|
| Тема | Sample of user-define window function and other things |
| Дата | |
| Msg-id | e08cc0400901080219v51e68a8qfa3732a421922bbb@mail.gmail.com обсуждение исходный текст |
| Ответы |
Re: Sample of user-define window function and other things
Re: Sample of user-define window function and other things |
| Список | pgsql-hackers |
Attached is a simple user-define window function as a test, which
calculates moving avg(). Writing this, I found that even with current
specification (i.e. limited frame clauses), user-define function can
emulate some kinds of moving frame for simple purpose.
CREATE OR REPLACE FUNCTION movavg(float8, int4) RETURNS float8 AS
'$libdir/moving', 'movavg'
LANGUAGE 'c' WINDOW;
SELECT depname, salary, movavg(salary::float8, 1) OVER (
PARTITION BY depname
ORDER BY salary
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
)
FROM empsalary;
And miscellaneous questions:
- CREATE FUNCTION command accepts WINDOW keyword for non-c language
like plpgsql. Don't we need to throw error?
- Is WinGetFuncArgInPartition()'s argument mark_pos required? For the
newbies to window functions, it seems a bit confusing, but
WinSetMarkPos() looks enough for the purpose AFAIK.
Regards,
--
Hitoshi Harada
Вложения
В списке pgsql-hackers по дате отправления: