> > 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];
oops. That was me randomly trying things I thought I understood. (I
thought I got all those :-)
> (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.
indeed I did. Still have the same problem, though:
create or replace function float8_jitter_add(float8[], interval)
returns float8[] as '
declare
v_old_state ALIAS FOR $1;
v_rtt ALIAS FOR $2;
v_state float8[];
BEGIN
IF v_old_state is NULL THEN
v_state = ''{0, 0, 0, 0}'';
ELSIF v_rtt IS NOT NULL THEN
if v_old_state[4] = 1 THEN
v_state[1] := v_old_state[2] + (v_old_state[3] - v_rtt);
v_state[2] := v_old_state[2] + 1;
END IF;
v_state[3] := v_rtt;
v_state[4] := 1;
ELSE
v_state[4] := 0;
END IF;
return v_state;
END;
' language 'plpgsql';
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
-Todd