Re: arrays and functions in plpgsql - Mailing list pgsql-novice

From Todd Kover
Subject Re: arrays and functions in plpgsql
Date
Msg-id 200409172356.i8HNuTrE024530@guinness.omniscient.com
Whole thread Raw
In response to Re: arrays and functions in plpgsql  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: arrays and functions in plpgsql
List 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

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: arrays and functions in plpgsql
Next
From: Tom Lane
Date:
Subject: Re: arrays and functions in plpgsql