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

Can you use an array of variables in a function?

From: "Frank Millman" <frank(at)chagford(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Can you use an array of variables in a function?
Date: 2004-12-31 10:07:57
Message-ID: 000801c4ef20$99d9db80$0501a8c0@frank (view raw or flat)
Thread:
Lists: pgsql-general
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.

For debugging, I added the following line before the return -
  raise notice ''ints[1] = '', _ints[1];

I then get 'syntax error at or near "["'.

Platform is 7.4.1 on Redhat 9.

TIA for any advice.

Frank Millman

Responses

pgsql-general by date

Next:From: Pavel StehuleDate: 2004-12-31 11:27:11
Subject: Re: Can you use an array of variables in a function?
Previous:From: SecrétariatDate: 2004-12-31 09:22:37
Subject: Re: Update rule

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