FAQ
Hello all,
Need ur help.I dont know wats wrong with the following fucntion.
create or replace function twoarray() returns setof integer as
'
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;
return next a[i][j];
end loop;
end loop;
return;
end;
'
language 'plpgsql';

when i execute the following statement i get an error saying 'array
subscript out of range'

select * from twoarray();
ERROR: array subscript out of range
CONTEXT: PL/pgSQL function "twoarray" line 8 at assignment

--
View this message in context: http://www.nabble.com/ERROR%3A-array-subscript-out-of-range-tp22992481p22992481.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

## Search Discussions

•  at Apr 10, 2009 at 8:18 pm ⇧

chinchu2005 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
a := '{{1,2,3,4,5,6,7,8,9,10},{1,2,3,4,5,6,7,8,9,10}}';

regards, tom lane
•  at Apr 11, 2009 at 4:03 am ⇧

chinchu2005 escribió:

Hello all,
Need ur help.I dont know wats wrong with the following fucntion.
create or replace function twoarray() returns setof integer as
'
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;
We just had this question on the spanish list. Somebody was kind enough
to write the answers down in the Wiki:
http://wiki.postgresql.org/wiki/Matrices_Multidimensionales_con_funciones

It is all in spanish, but the code examples should be helpful
nonetheless.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

## Related Discussions

Discussion Overview
 group pgsql-general categories postgresql posted Apr 10, '09 at 6:20p active Apr 11, '09 at 4:03a posts 3 users 3 website postgresql.org irc #postgresql

### 3 users in discussion

Content

People

Support

Translate

site design / logo © 2021 Grokbase