Re: ERROR: array subscript out of range

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: chinchu2005 <chinchu2005(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ERROR: array subscript out of range
Date: 2009-04-10 20:18:44
Message-ID: 261.1239394724@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

chinchu2005 <chinchu2005(at)gmail(dot)com> writes:
> declare
> i integer;
> j integer;
> a integer[][];
> begin
> for i in 1..10 loop
> for j in 1..2 loop
> a[i][j]:=i*j;

This isn't going to work --- it implies dynamically resizing the array,
and plpgsql isn't smart enough to do that for a multidimensional array.
Do you actually need a 2-D array here? If so you'll have to initialize
it to the right dimensions to start with, eg with
a := '{{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}}';

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pedro Doria Meunier 2009-04-11 01:47:53 Re: Internationalization
Previous Message Justin 2009-04-10 19:30:27 Re: Internationalization