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

Help me,please
--
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

  • Tom Lane 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
    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
  • Alvaro Herrera 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 Navigation
viewthread | post
Discussion Overview
grouppgsql-general @
categoriespostgresql
postedApr 10, '09 at 6:20p
activeApr 11, '09 at 4:03a
posts3
users3
websitepostgresql.org
irc#postgresql

People

Translate

site design / logo © 2021 Grokbase