Sample of user-define window function and other things - Mailing list pgsql-hackers

From Hitoshi Harada
Subject Sample of user-define window function and other things
Date
Msg-id e08cc0400901080219v51e68a8qfa3732a421922bbb@mail.gmail.com
Whole thread Raw
Responses Re: Sample of user-define window function and other things  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Sample of user-define window function and other things  (Peter Eisentraut <peter_e@gmx.net>)
List 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

Attachment

pgsql-hackers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: Re: Latest version of Hot Standby patch
Next
From: "Rushabh Lathia"
Date:
Subject: Segmentation fault on PG 8.4 CVS head