Skip site navigation (1) Skip section navigation (2)

Re: arrays and functions in plpgsql

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: (view raw, whole thread or download thread mbox)
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 '
        v_old_state ALIAS FOR $1;
        v_rtt ALIAS FOR $2;
        v_state[3] float8;
        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;
                v_state[4] := 0;
        END IF;
        return v_state;
' 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,


pgsql-novice by date

Next:From: Tom LaneDate: 2004-09-18 00:10:48
Subject: Re: arrays and functions in plpgsql
Previous:From: Tom LaneDate: 2004-09-17 23:16:14
Subject: Re: arrays and functions in plpgsql

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group