| From: | Pavel Stehule <stehule(at)kix(dot)fsv(dot)cvut(dot)cz> |
|---|---|
| To: | Frank Millman <frank(at)chagford(dot)com> |
| Cc: | pgsql-general(at)postgresql(dot)org |
| Subject: | Re: Can you use an array of variables in a function? |
| Date: | 2004-12-31 11:27:11 |
| Message-ID: | Pine.LNX.4.44.0412311222360.20600-100000@kix.fsv.cvut.cz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hello,
You can use arrays in PL/pgSQL without problems. But You need first
init array on not NULL value.
CREATE OR REPLACE FUNCTION foo(int) RETURNS int AS $$
DECLARE x int[] = '{}';
BEGIN x[1] := $1;
RETURN x[1];
END; $$ LANGUAGE plpgsql;
regards
Pavel
> Hi all
>
> Is it possible to use an array of variables in a PL/pgSQL function?
>
> Here is a trivial example of what I am trying to do.
>
> ------------------------
> create or replace function fmfunc(int) returns int as '
> declare
> _int alias for $1;
> _ints int[3];
> begin
> _ints[1] = _int * 2;
> _ints[2] = _int * 4;
> _ints[3] = _int * 8;
> return _ints[3];
> end;'
> language 'plpgsql';
> ------------------------
>
> SELECT fmfunc(3) runs without any errors, but it returns null.
>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Clodoaldo Pinto | 2004-12-31 11:59:32 | Re: Postgresql website issues. |
| Previous Message | Frank Millman | 2004-12-31 10:07:57 | Can you use an array of variables in a function? |