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-18 00:31:13
Message-ID: 200409180031.i8I0VDic003360@guinness.omniscient.com (view raw or flat)
Thread:
Lists: pgsql-novice
 > >         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

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2004-09-18 01:41:13
Subject: Re: arrays and functions in plpgsql
Previous:From: Tom LaneDate: 2004-09-18 00:10:48
Subject: Re: arrays and functions in plpgsql

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