forked from 2ndQuadrant/fixeddecimal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfixeddecimal--xlaggs.sql
57 lines (45 loc) · 1.41 KB
/
fixeddecimal--xlaggs.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- Aggregate Support
CREATE FUNCTION fixeddecimalaggstatecombine(FIXEDDECIMALAGGSTATE, FIXEDDECIMALAGGSTATE)
RETURNS FIXEDDECIMALAGGSTATE
AS 'fixeddecimal', 'fixeddecimalaggstatecombine'
LANGUAGE C IMMUTABLE;
CREATE FUNCTION fixeddecimal_avg_accum(FIXEDDECIMALAGGSTATE, FIXEDDECIMAL)
RETURNS FIXEDDECIMALAGGSTATE
AS 'fixeddecimal', 'fixeddecimal_avg_accum'
LANGUAGE C IMMUTABLE;
CREATE FUNCTION fixeddecimal_sum(FIXEDDECIMALAGGSTATE)
RETURNS FIXEDDECIMAL
AS 'fixeddecimal', 'fixeddecimal_sum'
LANGUAGE C IMMUTABLE;
CREATE FUNCTION fixeddecimal_avg(FIXEDDECIMALAGGSTATE)
RETURNS FIXEDDECIMAL
AS 'fixeddecimal', 'fixeddecimal_avg'
LANGUAGE C IMMUTABLE;
CREATE AGGREGATE min(FIXEDDECIMAL) (
SFUNC = fixeddecimalsmaller,
CFUNC = fixeddecimalsmaller,
CTYPE = FIXEDDECIMAL,
STYPE = FIXEDDECIMAL,
SORTOP = <
);
CREATE AGGREGATE max(FIXEDDECIMAL) (
SFUNC = fixeddecimallarger,
CFUNC = fixeddecimallarger,
CTYPE = FIXEDDECIMAL,
STYPE = FIXEDDECIMAL,
SORTOP = >
);
CREATE AGGREGATE sum(FIXEDDECIMAL) (
SFUNC = fixeddecimal_avg_accum,
CFUNC = fixeddecimalaggstatecombine,
CTYPE = FIXEDDECIMALAGGSTATE,
FINALFUNC = fixeddecimal_sum,
STYPE = FIXEDDECIMALAGGSTATE
);
CREATE AGGREGATE avg(FIXEDDECIMAL) (
SFUNC = fixeddecimal_avg_accum,
CFUNC = fixeddecimalaggstatecombine,
CTYPE = FIXEDDECIMALAGGSTATE,
FINALFUNC = fixeddecimal_avg,
STYPE = FIXEDDECIMALAGGSTATE
);