Re: Arrays in pl/pgsql functions - Mailing list pgsql-admin

From Joe Conway
Subject Re: Arrays in pl/pgsql functions
Date
Msg-id 3F16E1D5.7080304@joeconway.com
Whole thread Raw
In response to Arrays in pl/pgsql functions  ("Donald Fraser" <demolish@cwgsy.net>)
List pgsql-admin
Donald Fraser wrote:
> Could someone be please inform me what the correct syntax for accessing arrays
> is or tell me if its not possible with pl/pgSQL functions.
>

It won't work in 7.3.x or before, as you've noted. In 7.4 this will work:

CREATE OR REPLACE FUNCTION test_arrays() RETURNS int4[] AS '
DECLARE
      test int4[] := ''{}'';
BEGIN
     test[1] := 1;
     RETURN test;
END ' LANGUAGE 'plpgsql';

regression=# select test_arrays();
  test_arrays
-------------
  {1}
(1 row)

Note that you have to initialize "test" to an empty array, because
otherwise you are trying to add an element to a NULL::int4[], the result
of which is still NULL.

Joe


pgsql-admin by date:

Previous
From: P G
Date:
Subject: Where can I find the release notes for 7.3.3?
Next
From: "Donald Fraser"
Date:
Subject: Re: Arrays in pl/pgsql functions