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