From: | Todd Kover <kovert(at)omniscient(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: arrays and functions in plpgsql |
Date: | 2004-09-17 23:56:29 |
Message-ID: | 200409172356.i8HNuTrE024530@guinness.omniscient.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
> 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?
Thanks. All your suggestions helped a bunch and make sense. Although
I'm running into an issue:
create or replace function float8_jitter_add(float8[], interval)
returns float8[3] as '
declare
v_old_state ALIAS FOR $1;
v_rtt ALIAS FOR $2;
v_state[3] float8;
BEGIN
IF v_state is NULL THEN
v_state = ''{0, 0, 0, 0}'';
ELSIF v_rtt IS NOT NULL THEN
if v_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
Near as I can tell, I'm not reassigning $1 (or v_old_state) and line 12
is the END IF, which looks to be to be ok as do the lines around it.
I'm probably missing something obvious..
thanks again,
-Todd
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2004-09-18 00:10:48 | Re: arrays and functions in plpgsql |
Previous Message | Tom Lane | 2004-09-17 23:16:14 | Re: arrays and functions in plpgsql |