Re: arrays in pl/pgsql - Mailing list pgsql-sql

From Tom Lane
Subject Re: arrays in pl/pgsql
Date
Msg-id 18350.1071546938@sss.pgh.pa.us
Whole thread Raw
In response to arrays in pl/pgsql  (Michael Shapiro <mshapiro@ncsa.uiuc.edu>)
List pgsql-sql
Michael Shapiro <mshapiro@ncsa.uiuc.edu> writes:
> I have tried the following (which doesn't work)
>     dn[1] := \'a\';
> The parser doesn't like the [ that follows dn.

I believe Joe Conway fixed this in 7.4.  Note that you also need to
initialize the array to something, because assigning to an element
of a NULL array still yields a NULL array result.  For example:

regression=# create or replace function foo() returns text as '
regression'# declare dn text[] := \'{}\';
regression'# begin
regression'#   dn[1] := \'a\';
regression'#   return dn[1];
regression'# end' language plpgsql;
CREATE FUNCTION
regression=# select foo();foo
-----a
(1 row)
        regards, tom lane


pgsql-sql by date:

Previous
From: Michael Shapiro
Date:
Subject: arrays in pl/pgsql
Next
From: Olivier Hubaut
Date:
Subject: Re: dump and schema