How to loop through multi-dimentional array in PL/PGSQL

Started by VENKTESH GUTTEDARover 9 years ago3 messagesgeneral
Jump to latest
#1VENKTESH GUTTEDAR
venkteshguttedar@gmail.com

Hello,

Please help me in accessing multi-dimentional array in postgresql
PL/PGSQL.

for i in array_lower(product_list, 1) .. array_upper(product_list, 1)
LOOP
product_list[i][0];
END LOOP;

Is the above code right?

Or is there any other way to access, i am getting null for
product_list[i][0];

Any help would be appreciated.

--
Regards :
Venktesh Guttedar.

In reply to: VENKTESH GUTTEDAR (#1)
Re: How to loop through multi-dimentional array in PL/PGSQL

On 09/12/16 06:35, VENKTESH GUTTEDAR wrote:

Hello,

Please help me in accessing multi-dimentional array in postgresql
PL/PGSQL.

for i in array_lower(product_list, 1) .. array_upper(product_list, 1)
LOOP
product_list[i][0];
END LOOP;

Is the above code right?

Or is there any other way to access, i am getting null for
product_list[i][0];

By default, PostgreSQL uses 1-based arrays (i.e. no [0] slot), so maybe
that's your problem.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

In reply to: Raymond O'Donnell (#2)
Re: How to loop through multi-dimentional array in PL/PGSQL

On 09/12/16 10:42, Raymond O'Donnell wrote:

On 09/12/16 06:35, VENKTESH GUTTEDAR wrote:

Hello,

Please help me in accessing multi-dimentional array in postgresql
PL/PGSQL.

for i in array_lower(product_list, 1) .. array_upper(product_list, 1)
LOOP
product_list[i][0];
END LOOP;

Is the above code right?

Or is there any other way to access, i am getting null for
product_list[i][0];

By default, PostgreSQL uses 1-based arrays (i.e. no [0] slot), so maybe
that's your problem.

I just tried it myself: doing this -

select ('{a, b, c}'::text[])[0]

- gives me NULL.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod@iol.ie

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general