Re: Arrays in pl/pgsql functions

From: "Donald Fraser" <demolish(at)cwgsy(dot)net>
To: "[ADMIN]" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Arrays in pl/pgsql functions
Date: 2003-07-17 18:10:33
Message-ID: 00ab01c34c8e$ba682400$1664a8c0@DEMOLITION
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Many thanks for clearing that one up.
I have avoided using arrays for the mean time and gone for the more elegant
solution of using an additional table. More flexible and powerful but, in the
simple case that I needed, meant more work... Roll on 7.4 !

Regards
Donald Fraser.

----- Original Message -----
From: "Joe Conway" <mail(at)joeconway(dot)com>
To: "Donald Fraser" <demolish(at)cwgsy(dot)net>
Cc: "[ADMIN]" <pgsql-admin(at)postgresql(dot)org>
Sent: Thursday, July 17, 2003 6:50 PM
Subject: Re: [ADMIN] Arrays in pl/pgsql functions

> 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
>
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2003-07-17 18:18:42 Re: Arrays in pl/pgsql functions
Previous Message Joe Conway 2003-07-17 17:50:13 Re: Arrays in pl/pgsql functions