![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have: create or replace function float8_jitter_sum(float8[]) returns float8 as ' declare v_state ALIAS FOR $1; v_avg float8; BEGIN v_avg := NULL; if v_state[1] != 0 THEN v_avg := v_state[0] / v_state[1]; END IF; return v_avg; END; ' language 'plpgsql'; |
|
create aggregate jitter ( basetype = interval, sfunc = float8_jitter_add, stype = float8[], finalfunc = float8_jitter_sum, initcond = '(NULL,NULL)' ); |
|
IF v_state is NULL THEN v_state[0] := 0; v_state[1] := 0; v_state[2] := NULL; |
#3
| |||
| |||
|
|
You'll have to invent some convention other than NULL for the third entry, also. Maybe use a 4-element array and let the 4th element be 1 or 0 according to whether the 3rd element is really meaningful? |
#4
| |||
| |||
|
|
v_state[3] float8; |
#5
| |||
| |||
|
|
v_state[3] float8; Hmm. I'm not sure what the plpgsql parser will make of that. I think you probably wanted v_state float8[3]; |
|
(note that you really want [4], not that it actually matters since PG doesn't enforce the array size; float8[] would do as well) Also, I think you need to change v_state to v_old_state in several more places than you did, or else assign v_old_state to v_state up front. |
#6
| |||
| |||
|
|
indeed I did. Still have the same problem, though: create or replace function float8_jitter_add(float8[], interval) ... testdb=# select float8_jitter_add('{.1,.2,.3,1}', 5); ERROR: "$1" is declared CONSTANT CONTEXT: compile of PL/pgSQL function "float8_jitter_add" near line 12 |
![]() |
| Thread Tools | |
| Display Modes | |
| |