Re: Multidimentional array access

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: VENKTESH GUTTEDAR <venkteshguttedar(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-general(at)postgresql(dot)org>
Subject: Re: Multidimentional array access
Date: 2016-12-09 15:17:42
Message-ID: CAFj8pRD_W-gUgc0MHhYw2vs7zp8pm0o2JEe2LgMub+nPq=xoWw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi

2016-12-09 16:05 GMT+01:00 VENKTESH GUTTEDAR <venkteshguttedar(at)gmail(dot)com>:

> Hello,
>
> I want to get the inner array in a multi dimentional array in a
> pl/pgsql procedure.
>
> Eg : {{1,2,3,4,5,6,7},{11,22,33,44,55,66,77}}
>
> for i in array_lower(Eg, 1) .. array_upper(Eg, 1)
> LOOP
> array_value = Eg[i]
> END LOOP;
>
> But Eg[i] is assigning null to array_value
>
> Help would be appreciated.
>

postgres=# do
$$
declare i int; j int; a int[];
begin
a := ARRAY[[1,2],[3,4]];
for i in array_lower(a,1) .. array_upper(a,1)
loop
for j in array_lower(a,2)..array_upper(a,2)
loop
raise notice 'a[%,%]=%', i,j,a[i][j];
end loop;
end loop;
end;
$$;
NOTICE: a[1,1]=1
NOTICE: a[1,2]=2
NOTICE: a[2,1]=3
NOTICE: a[2,2]=4
DO
Time: 142,078 ms

What is your PostgreSQL version?

Regards

Pavel

>
>
> --
> Regards :
> Venktesh Guttedar.
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2016-12-09 15:23:19 Re: When to use COMMENT vs --
Previous Message VENKTESH GUTTEDAR 2016-12-09 15:05:46 Multidimentional array access