Re: Passing array to PL/SQL and looping - Mailing list pgsql-sql

From Ian Barwick
Subject Re: Passing array to PL/SQL and looping
Date
Msg-id 200209290025.06378.barwick@gmx.net
Whole thread Raw
In response to Re: Passing array to PL/SQL and looping  ("Josh Berkus" <josh@agliodbs.com>)
Responses Re: Passing array to PL/SQL and looping
List pgsql-sql
On Friday 27 September 2002 18:04, Josh Berkus wrote:
> Greg,
>
> > CREATE FUNCTION test_array( ) RETURNS VARCHAR[] AS '
> > DECLARE
> >     return_array VARCHAR[];
> > BEGIN
> >     return_array[0] := ''test'';
> >     return_array[1] := ''test 1'';
> >     return_array[2] := ''test 2'';
> > RETURN (return_array);
> > END;'
> > LANGUAGE 'plpgsql';
>
> No, it's not possible to do the above.   This is a flaw in the current
> implementation of PL/pgSQL that will not be resolved until we attract
> some new Postgres hackers who really care about upgrading PL/pgSQL.
>
> Currently, if you want to use an array, it has to be passed as a
> parameter, or come from an external table.   You cannot declare an
> Array data type.  Annoying, really.

If I replace the return_array allocations in the above example with this
line:
 return_array := ''{ ''''test'''', ''''test 1'''', ''''test 2''''}'';

it _seems_ to work as expected, at least in 7.3b1., e.g.

test=> select array_dims(test_array) from test_array();array_dims
------------[1:3]
(1 row)


Ian Barwick
barwick@gmx.net



pgsql-sql by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: [GENERAL] function return multiply rows
Next
From: Roland Roberts
Date:
Subject: Re: Passing array to PL/SQL and looping